diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 7cff64a3da..1d9100f216 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -3,12 +3,14 @@ package info.nightscout.androidaps.plugins.Overview; import android.annotation.SuppressLint; import android.app.Activity; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; +import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; @@ -72,6 +74,7 @@ import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; +import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -79,6 +82,7 @@ public class OverviewFragment extends Fragment { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); private static OverviewPlugin overviewPlugin = new OverviewPlugin(); + private SharedPreferences prefs; public static OverviewPlugin getPlugin() { return overviewPlugin; @@ -121,6 +125,8 @@ public class OverviewFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + View view = inflater.inflate(R.layout.overview_fragment, container, false); bgView = (TextView) view.findViewById(R.id.overview_bg); timeAgoView = (TextView) view.findViewById(R.id.overview_timeago); @@ -578,8 +584,16 @@ public class OverviewFragment extends Fragment { long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding long fromTime = toTime - hoursToFetch * 60 * 60 * 1000L; - Double lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units); - Double highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); + Double lowLine = SafeParse.stringToDouble(prefs.getString("low_mark", "0")); + Double highLine = SafeParse.stringToDouble(prefs.getString("high_mark", "0")); + + if (lowLine < 1){ + lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units); + } + + if(highLine < 1){ + highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); + } BarGraphSeries basalsSeries = null; LineGraphSeries seriesLow = null; @@ -662,6 +676,7 @@ public class OverviewFragment extends Fragment { } maxBgValue = NSProfile.fromMgdlToUnits(maxBgValue, units); maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; + if(highLine > maxBgValue) maxBgValue = highLine; Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); BgReading[] inRange = new BgReading[inRangeArray.size()]; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java index ee6ff83a1d..8f4e7f9be2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java @@ -39,13 +39,14 @@ public class WearFragment extends Fragment implements FragmentBase { } }); + view.findViewById(R.id.wear_opensettings).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + getPlugin(getContext()).openSettings(); + } + }); return view; } - - - //TODO Adrian: setting for short/long status string - //TODO Adrian: resend buttons - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 322ff66263..a771607336 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterServi public class WearPlugin implements PluginBase { static boolean fragmentEnabled = true; - static boolean fragmentVisible = false; + static boolean fragmentVisible = true; private static WatchUpdaterService watchUS; private final Context ctx; @@ -94,25 +94,19 @@ public class WearPlugin implements PluginBase { void resendDataToWatch(){ ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND)); - } - - /* @Subscribe - public void onStatusEvent(final EventPreferenceChange ev) { - - //TODO Adrian: probably a high/low mark change? Send it instantly? - sendDataToWatch(); + void openSettings(){ + ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)); } + @Subscribe - public void onStatusEvent(final EventRefreshGui ev) { - - //TODO Adrian: anything here that is not covered by other cases? - sendDataToWatch(); + public void onStatusEvent(final EventPreferenceChange ev) { + //possibly new high or low mark + resendDataToWatch(); } -*/ @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { sendDataToWatch(true, true, false); @@ -125,7 +119,6 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventNewBG ev) { - sendDataToWatch(true, true, true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 9df048d15a..f835df7171 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -30,9 +30,11 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; +import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SafeParse; public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, @@ -151,21 +153,38 @@ public class WatchUpdaterService extends WearableListenerService implements } private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) { - Double highMark = 170d; //in mg/dl TODO: dynamically read this? - Double lowMark = 70d; + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + + + Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); + Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); + + //convert to mg/dl + if (! profile.getUnits().equals(Constants.MGDL)){ + lowLine *= Constants.MMOLL_TO_MGDL; + highLine *= Constants.MMOLL_TO_MGDL; + + } + + if (lowLine < 1){ + lowLine = OverviewPlugin.bgTargetLow; + } + + if(highLine < 1){ + highLine = OverviewPlugin.bgTargetHigh; + } long sgvLevel = 0l; - if (lastBG.value > highMark) { + if (lastBG.value > highLine) { sgvLevel = 1; - } else if (lastBG.value < lowMark) { + } else if (lastBG.value < lowLine) { sgvLevel = -1; } DataMap dataMap = new DataMap(); int battery = getBatteryLevel(getApplicationContext()); - NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits())); - dataMap.putDouble("timestamp", lastBG.getTimeIndex()); //TODO: change that to long (was like that in NW) + dataMap.putDouble("timestamp", lastBG.getTimeIndex()); if(glucoseStatus == null) { dataMap.putString("slopeArrow", "" ); dataMap.putString("delta", ""); @@ -179,8 +198,8 @@ public class WatchUpdaterService extends WearableListenerService implements dataMap.putLong("sgvLevel", sgvLevel); dataMap.putInt("batteryLevel", (battery>=30)?1:0); dataMap.putDouble("sgvDouble", lastBG.value); - dataMap.putDouble("high", highMark); - dataMap.putDouble("low", lowMark); + dataMap.putDouble("high", highLine); + dataMap.putDouble("low", lowLine); return dataMap; } @@ -347,37 +366,6 @@ public class WatchUpdaterService extends WearableListenerService implements } } - - - - - - //TODO: Adrian: replace fake data - /* long from = startTimeWindow; - long to = (now + from)/2; - double amount = 0.5; - - - - - from = (long)(startTimeWindow + (1/8d)*(now - startTimeWindow)); - double fromBasal = 0.5; - to = (long)(startTimeWindow + (2/8d)*(now - startTimeWindow)); - double toBasal = 0.5; - amount = 3; - temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); - - - from = (long)(startTimeWindow + (6/8d)*(now - startTimeWindow)); - fromBasal = 0.8; - to = (long)(startTimeWindow + (7/8d)*(now - startTimeWindow)); - toBasal = 0.8; - amount = 0; - temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); - -*/ - - DataMap dm = new DataMap(); dm.putDataMapArrayList("basals", basals); dm.putDataMapArrayList("temps", temps); @@ -421,9 +409,6 @@ public class WatchUpdaterService extends WearableListenerService implements if (googleApiClient.isConnected()) { String status = ""; - - //TODO Adrian: Setting if short or medium string. - boolean shortString = true; //Temp basal diff --git a/app/src/main/res/layout/wear_fragment.xml b/app/src/main/res/layout/wear_fragment.xml index c203c7b298..e8ab87bcf9 100644 --- a/app/src/main/res/layout/wear_fragment.xml +++ b/app/src/main/res/layout/wear_fragment.xml @@ -20,7 +20,20 @@ android:layout_marginTop="3dp" android:layout_weight="0.5" android:text="Resend All Data" - android:textColor="@color/colorProfileSwitchButton" /> + android:textColor="@color/colorTreatmentButton" /> + +