From e2c2f49f6f7f34e96052b3a0d0a5dda5348c651f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 28 Dec 2016 14:57:11 +0100 Subject: [PATCH 01/15] MM640g bg source --- app/src/main/AndroidManifest.xml | 2 + .../info/nightscout/androidaps/MainApp.java | 2 + .../androidaps/Services/DataService.java | 64 +++++++++++++++++++ .../androidaps/Services/Intents.java | 2 + .../SourceMM640g/SourceMM640gFragment.java | 16 +++++ .../SourceMM640g/SourceMM640gPlugin.java | 56 ++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 143 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f6e693e611..d49ee22092 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -63,6 +63,8 @@ + + diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index e2e7eabd89..9e609a3b15 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment; import info.nightscout.androidaps.plugins.SafetyFragment.SafetyFragment; import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment; +import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment; import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment; @@ -89,6 +90,7 @@ public class MainApp extends Application { if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin()); pluginsList.add(SourceXdripFragment.getPlugin()); pluginsList.add(SourceNSClientFragment.getPlugin()); + pluginsList.add(SourceMM640gFragment.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 95a6b81b68..734e3defaf 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -42,6 +42,7 @@ import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; +import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; @@ -55,6 +56,7 @@ public class DataService extends IntentService { boolean xDripEnabled = false; boolean nsClientEnabled = true; + boolean mm640gEnabled = false; public DataService() { super("DataService"); @@ -69,9 +71,15 @@ public class DataService extends IntentService { if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { xDripEnabled = true; nsClientEnabled = false; + mm640gEnabled = false; } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) { xDripEnabled = false; nsClientEnabled = true; + mm640gEnabled = false; + } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) { + xDripEnabled = false; + nsClientEnabled = false; + mm640gEnabled = true; } boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class); @@ -85,6 +93,10 @@ public class DataService extends IntentService { if (xDripEnabled) { handleNewDataFromXDrip(intent); } + } else if (Intents.NS_EMULATOR.equals(action)) { + if (mm640gEnabled) { + handleNewDataFromMM640g(intent); + } } else if (Intents.ACTION_NEW_SGV.equals(action)) { // always handle SGV if NS-Client is the source if (nsClientEnabled) { @@ -171,6 +183,58 @@ public class DataService extends IntentService { MainApp.bus().post(new EventNewBG()); } + private void handleNewDataFromMM640g(Intent intent) { + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + final String collection = bundle.getString("collection"); + if (collection == null) return; + + if (collection.equals("entries")) { + final String data = bundle.getString("data"); + + if ((data != null) && (data.length() > 0)) { + try { + final JSONArray json_array = new JSONArray(data); + for (int i = 0; i < json_array.length(); i++) { + final JSONObject json_object = json_array.getJSONObject(i); + final String type = json_object.getString("type"); + switch (type) { + case "sgv": + BgReading bgReading = new BgReading(); + + bgReading.value = json_object.getDouble("sgv"); + bgReading.direction = json_object.getString("direction"); + bgReading.timeIndex = json_object.getLong("date"); + bgReading.raw = json_object.getDouble("sgv"); + + if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) { + if (Config.logIncommingBG) + log.debug("Ignoring old MM640g BG " + bgReading.toString()); + return; + } + + if (Config.logIncommingBG) + log.debug("MM640g BG " + bgReading.toString()); + + try { + MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); + } catch (SQLException e) { + e.printStackTrace(); + } + break; + default: + log.debug("Unknown entries type: " + type); + } + } + } catch (JSONException e) { + log.error("Got JSON exception: " + e); + } + } + } + MainApp.bus().post(new EventNewBG()); + } + private void handleNewDataFromNSClient(Intent intent) { Bundle bundles = intent.getExtras(); if (bundles == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java index 63ef83e298..e46071e7ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java @@ -29,4 +29,6 @@ public interface Intents { String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw"; String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData"; + + String NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java new file mode 100644 index 0000000000..f43dc6ada7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.SourceMM640g; + + +import android.support.v4.app.Fragment; + +import info.nightscout.androidaps.interfaces.FragmentBase; + +public class SourceMM640gFragment extends Fragment implements FragmentBase { + + private static SourceMM640gPlugin sourceMM640gPlugin = new SourceMM640gPlugin(); + + public static SourceMM640gPlugin getPlugin() { + return sourceMM640gPlugin; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java new file mode 100644 index 0000000000..f7f0de23fb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java @@ -0,0 +1,56 @@ +package info.nightscout.androidaps.plugins.SourceMM640g; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; + +/** + * Created by mike on 05.08.2016. + */ +public class SourceMM640gPlugin implements PluginBase, BgSourceInterface { + boolean fragmentEnabled = true; + + @Override + public String getFragmentClass() { + return SourceMM640gFragment.class.getName(); + } + + @Override + public int getType() { + return PluginBase.BGSOURCE; + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.MM640g); + } + + @Override + public boolean isEnabled(int type) { + return type == BGSOURCE && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + + } + + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 87b200db28..586bc7176b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -387,4 +387,5 @@ BG: Last BG: MDI + MM640g From 86f5aec0bb44140c16d22ae3bceff6cb14a1b21a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Jan 2017 13:45:03 +0100 Subject: [PATCH 02/15] disable visible control when plugin is not enabled --- .../plugins/ConfigBuilder/ConfigBuilderFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index e15f97d5fb..7c23346711 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -205,6 +205,10 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase { holder.checkboxVisible.setEnabled(false); } + if (!plugin.isEnabled(type)) { + holder.checkboxVisible.setEnabled(false); + } + // Hide enabled control and force enabled plugin if there is only one plugin available if (type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.TEMPBASAL || type == PluginBase.PROFILE) if (pluginList.size() < 2) { From 9edb5c9a6645bcab19ed99837f55078f428ab495 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Jan 2017 14:00:59 +0100 Subject: [PATCH 03/15] draw basals only if pump is tempbasal capable --- .../plugins/Overview/OverviewFragment.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) 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 c7760d7af7..2b9ee97d95 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 @@ -668,27 +668,29 @@ public class OverviewFragment extends Fragment { Double maxBasalValueFound = 0d; long now = new Date().getTime(); - List basalArray = new ArrayList(); - for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { - TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time)); - Double basal = 0d; - if (tb != null) - basalArray.add(new BarDataPoint(time, basal = tb.tempBasalConvertedToAbsolute(new Date(time)), true)); - else - basalArray.add(new BarDataPoint(time, basal = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false)); - maxBasalValueFound = Math.max(maxBasalValueFound, basal); - } - BarDataPoint[] basal = new BarDataPoint[basalArray.size()]; - basal = basalArray.toArray(basal); - bgGraph.addSeries(basalsSeries = new BarGraphSeries(basal)); - basalsSeries.setValueDependentColor(new ValueDependentColor() { - @Override - public int get(DataPoint data) { - BarDataPoint point = (BarDataPoint) data; - if (point.isTempBasal) return Color.BLUE; - else return Color.CYAN; + if (pump.getPumpDescription().isTempBasalCapable) { + List basalArray = new ArrayList(); + for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time)); + Double basal = 0d; + if (tb != null) + basalArray.add(new BarDataPoint(time, basal = tb.tempBasalConvertedToAbsolute(new Date(time)), true)); + else + basalArray.add(new BarDataPoint(time, basal = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false)); + maxBasalValueFound = Math.max(maxBasalValueFound, basal); } - }); + BarDataPoint[] basal = new BarDataPoint[basalArray.size()]; + basal = basalArray.toArray(basal); + bgGraph.addSeries(basalsSeries = new BarGraphSeries(basal)); + basalsSeries.setValueDependentColor(new ValueDependentColor() { + @Override + public int get(DataPoint data) { + BarDataPoint point = (BarDataPoint) data; + if (point.isTempBasal) return Color.BLUE; + else return Color.CYAN; + } + }); + } // set manual x bounds to have nice steps bgGraph.getViewport().setMaxX(toTime); @@ -784,10 +786,12 @@ public class OverviewFragment extends Fragment { bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines); // set second scale - bgGraph.getSecondScale().addSeries(basalsSeries); - bgGraph.getSecondScale().setMinY(0); - bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); - bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide + if (pump.getPumpDescription().isTempBasalCapable) { + bgGraph.getSecondScale().addSeries(basalsSeries); + bgGraph.getSecondScale().setMinY(0); + bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); + bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide + } } From ef2e7b1a62939d0587e1e2bafbe32a67aeb3c6d3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Jan 2017 14:19:35 +0100 Subject: [PATCH 04/15] show basal line only if pump is tempbasal capable --- .../androidaps/plugins/Overview/OverviewFragment.java | 10 +++++++++- app/src/main/res/layout/overview_fragment.xml | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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 2b9ee97d95..5cfd090a0c 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 @@ -101,6 +101,7 @@ public class OverviewFragment extends Fragment { TextView avgdeltaView; TextView runningTempView; TextView baseBasalView; + LinearLayout basalLayout; TextView activeProfileView; TextView iobView; TextView apsModeView; @@ -146,6 +147,7 @@ public class OverviewFragment extends Fragment { avgdeltaView = (TextView) view.findViewById(R.id.overview_avgdelta); runningTempView = (TextView) view.findViewById(R.id.overview_runningtemp); baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal); + basalLayout = (LinearLayout) view.findViewById(R.id.overview_basallayout); activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); iobView = (TextView) view.findViewById(R.id.overview_iob); @@ -521,7 +523,13 @@ public class OverviewFragment extends Fragment { cancelTempLayout.setVisibility(View.GONE); runningTempView.setVisibility(View.GONE); } - baseBasalView.setText(DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h"); + + if (pump.getPumpDescription().isTempBasalCapable) { + basalLayout.setVisibility(View.VISIBLE); + baseBasalView.setText(DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h"); + } else { + basalLayout.setVisibility(View.GONE); + } if (profile != null && profile.getActiveProfile() != null) activeProfileView.setText(profile.getActiveProfile()); diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 517eae9577..12c183d9e8 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -118,6 +118,7 @@ From 4408146f231808439cf862fb6ab20b5588121013 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Jan 2017 14:34:57 +0100 Subject: [PATCH 05/15] disable entering basals in profiles only if pump is not tempbasal capable --- .../CircadianPercentageProfileFragment.java | 8 ++++++++ .../plugins/LocalProfile/LocalProfileFragment.java | 6 ++++++ .../plugins/SimpleProfile/SimpleProfileFragment.java | 7 +++++++ .../res/layout/circadianpercentageprofile_fragment.xml | 1 + app/src/main/res/layout/simpleprofile_fragment.xml | 1 + 5 files changed, 23 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 0bf490abb6..9fd678e0d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.FragmentBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.utils.DecimalFormatter; @@ -55,6 +56,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag TextView profileView; TextView baseprofileIC; TextView baseprofileBasal; + LinearLayout baseprofileBasalLayout; TextView baseprofileISF; Button profileswitchButton; ImageView percentageIcon; @@ -79,6 +81,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview); baseprofileBasal = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal); + baseprofileBasalLayout = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout); baseprofileIC = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofileic); baseprofileISF = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofileisf); percentageIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_percentageicon); @@ -89,6 +92,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag iceditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_icedit); isfeditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_isfedit); + PumpInterface pump = MainApp.getConfigBuilder(); + if (!pump.getPumpDescription().isTempBasalCapable) { + layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout).setVisibility(View.GONE); + } + mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl); mmolView.setChecked(circadianPercentageProfilePlugin.mmol); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java index 401344d4df..cc891eb98a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.FragmentBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.utils.SafeParse; @@ -70,6 +71,11 @@ public class LocalProfileFragment extends Fragment implements FragmentBase { targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label), getPlugin().targetLow, getPlugin().targetHigh, new DecimalFormat("0.0"), save); profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch); + PumpInterface pump = MainApp.getConfigBuilder(); + if (!pump.getPumpDescription().isTempBasalCapable) { + layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE); + } + onStatusEvent(null); mgdlView.setChecked(localProfilePlugin.mgdl); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java index 1d0381ce3b..22e293a023 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.FragmentBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -68,6 +69,12 @@ public class SimpleProfileFragment extends Fragment implements FragmentBase { targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh); profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch); + PumpInterface pump = MainApp.getConfigBuilder(); + if (!pump.getPumpDescription().isTempBasalCapable) { + layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE); + layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE); + } + onStatusEvent(null); mgdlView.setChecked(simpleProfilePlugin.mgdl); diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index da2a23b4cd..db5067d881 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -110,6 +110,7 @@ android:layout_height="wrap_content" android:background="@color/cardColorBackground" android:orientation="horizontal" + android:id="@+id/circadianpercentageprofile_baseprofilebasal_layout" android:textAppearance="?android:attr/textAppearanceSmall"> From fded515ac16ac4e98ee7d5a51b72a6720269a3e6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Jan 2017 20:22:23 +0100 Subject: [PATCH 06/15] fix TimeListEdit when fragment is restored --- app/src/main/java/info/nightscout/utils/TimeListEdit.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index b1abfb6849..f3975e3e7a 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -84,23 +84,29 @@ public class TimeListEdit { for (int i = 0; i < itemsCount(); i++) { View childview = inflater.inflate(R.layout.timelistedit_element, layout, false); + childview.setId(View.generateViewId()); final Spinner timeSpinner = (Spinner) childview.findViewById(R.id.timelistedit_time); + timeSpinner.setId(View.generateViewId()); int previous = i == 0 ? -1 * ONEHOURINSECONDS : secondFromMidnight(i - 1); int next = i == itemsCount() - 1 ? 24 * ONEHOURINSECONDS : secondFromMidnight(i + 1); if (i == 0) next = ONEHOURINSECONDS; fillSpinner(timeSpinner, secondFromMidnight(i), previous, next); final EditText editText1 = (EditText) childview.findViewById(R.id.timelistedit_edit1); + editText1.setId(View.generateViewId()); fillNumber(editText1, value1(i)); final EditText editText2 = ((EditText) childview.findViewById(R.id.timelistedit_edit2)); fillNumber(editText2, value2(i)); + editText2.setId(View.generateViewId()); if (data2 == null) { editText2.setVisibility(View.GONE); } ImageView addbutton = (ImageView) childview.findViewById(R.id.timelistedit_add); + addbutton.setId(View.generateViewId()); ImageView removebutton = (ImageView) childview.findViewById(R.id.timelistedit_remove); + removebutton.setId(View.generateViewId()); if (itemsCount() == 1 && i == 0) { removebutton.setVisibility(View.GONE); From 9c40e4af34cadc421818a626d658e88493e9521a Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 1 Jan 2017 21:46:25 +0100 Subject: [PATCH 07/15] Dismiss editing when fragment is paused --- .../CircadianPercentageProfileFragment.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 0bf490abb6..a9afb13bbb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -344,6 +344,12 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag @Override public void onPause() { super.onPause(); + + if (basalEditDialog != null && basalEditDialog.isVisible()) { + basalEditDialog.dismiss(); + } + basalEditDialog = null; + MainApp.bus().unregister(this); } From f3551dda7ffe181985b8864ca1571dbe69433b7f Mon Sep 17 00:00:00 2001 From: viktoria Date: Mon, 2 Jan 2017 16:44:20 +0100 Subject: [PATCH 08/15] german translation --- app/src/main/res/values-de/strings.xml | 43 +++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index fc536ee468..c6313d7dbf 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -141,7 +141,7 @@ Current temp Gate: Objective: - Objectives + Zielsetzungen KEIN PROFIL GESETZT NSClient nicht installiert. Record lost! Verwende absolute statt prozentuelle Basalwerte beim Upload zu NightScout @@ -161,7 +161,6 @@ Eingegeben durch Anderes Split - Konfigurations Builder Constraints Generell Treatments @@ -204,7 +203,7 @@ Kommentar Verbunden Verbinden - Puempen Verbindungsfehler + Pumpen Verbindungsfehler DanaR Blueetooth Gerät Pumpen IOB: DanaR Pumpen Einstellungen @@ -222,15 +221,14 @@ Profil anzeigen DanaR Profil Einstellungen DIA [h] - Carbs absorption rate + Kohlehydrahte Absorptionsrate Manuell Einheiten (Tag) ungültige Eingabe Wert nicht korrekt gesetzt ausgewähltes Gerät nicht gefunden - ABWEISEN - Verordnet - Einbenutzervereinbarung + VERWERFEN + Endbenutzervereinbarung Ich verstehe und stimme zu darf nicht eingestzt werden um med. Eintscheidungen zu treffen Fehler beim aktualisieren der Basalrate @@ -257,9 +255,9 @@ Alarme Bolus Kohlenhydrate - Inslin-Tagesmengen + Insulin-Tagesmengen Fehler - Glucose + Glukose Füllmenge Unterbrechungen Pumpen-Passwort @@ -279,7 +277,7 @@ Aktionen Android APS gestartet Loop deaktiviert - Füllbolus-Standardmengen + Vorfüll-Standardmengen Bitte vergewissern Sie sich, dass die Menge der Spezifikation des Katheters entspricht. Zu NightScout nur hochladen (kein sync) Bitte deaktivieren Sie \"Zu NightScout nur hochladen\" um dieses Feature zu nutzen. @@ -288,7 +286,30 @@ Verstopfung Abgegeben %.2fU werden abgegeben werden - Füllen + Vorfüllen / Füllen Hochladen Spanish + Basalrate: + Basisprofil: + Pumpenbatterie entladen + Basal Temp Ende + neu laden + Hoch Markierung + Niedrig Markierung + Niedrige Batterie + Pumpe ist beschäftigt + Pumpenfehler + an Pumpe senden + Zielbereich: + Einheiten: + Falscher Pumpentreiber ausgewählt + Befüllen + EasyUI mode in Pumpe deaktivieren + Basal-Stunde + Knopf 1 + Knopf 2 + Knopf 3 + Absorptionsrate: + Config Builder + vor %d min From fe75298263dc88c3769e7a7ff9bef37b9218a013 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 3 Jan 2017 10:24:08 +0100 Subject: [PATCH 09/15] safer display values in openapsma fragment --- .../plugins/OpenAPSMA/OpenAPSMAFragment.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java index a3838d53a6..86cd729dcb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.FragmentBase; +import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSMAUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSMAUpdateResultGui; import info.nightscout.utils.JSONFormatter; @@ -101,14 +102,20 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, activity.runOnUiThread(new Runnable() { @Override public void run() { - if (getPlugin().lastAPSResult != null) { - glucoseStatusView.setText(JSONFormatter.format(getPlugin().lastDetermineBasalAdapterJS.getGlucoseStatusParam())); - currentTempView.setText(JSONFormatter.format(getPlugin().lastDetermineBasalAdapterJS.getCurrentTempParam())); - iobDataView.setText(JSONFormatter.format(getPlugin().lastDetermineBasalAdapterJS.getIobDataParam())); - profileView.setText(JSONFormatter.format(getPlugin().lastDetermineBasalAdapterJS.getProfileParam())); - mealDataView.setText(JSONFormatter.format(getPlugin().lastDetermineBasalAdapterJS.getMealDataParam())); - resultView.setText(JSONFormatter.format(getPlugin().lastAPSResult.json)); - requestView.setText(getPlugin().lastAPSResult.toSpanned()); + DetermineBasalResult lastAPSResult = getPlugin().lastAPSResult; + if (lastAPSResult != null) { + resultView.setText(JSONFormatter.format(lastAPSResult.json)); + requestView.setText(lastAPSResult.toSpanned()); + } + DetermineBasalAdapterJS determineBasalAdapterJS = getPlugin().lastDetermineBasalAdapterJS; + if (determineBasalAdapterJS != null) { + glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterJS.getGlucoseStatusParam())); + currentTempView.setText(JSONFormatter.format(determineBasalAdapterJS.getCurrentTempParam())); + iobDataView.setText(JSONFormatter.format(determineBasalAdapterJS.getIobDataParam())); + profileView.setText(JSONFormatter.format(determineBasalAdapterJS.getProfileParam())); + mealDataView.setText(JSONFormatter.format(determineBasalAdapterJS.getMealDataParam())); + } + if (getPlugin().lastAPSRun != null) { lastRunView.setText(getPlugin().lastAPSRun.toLocaleString()); } } From f3f6a911aeca66ce8e8b55ffed2d35814d9b176e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 3 Jan 2017 19:06:35 +0100 Subject: [PATCH 10/15] use android.text.format.DateUtils --- .../nightscout/androidaps/db/TempBasal.java | 8 +++--- .../nightscout/androidaps/db/Treatment.java | 3 +-- .../Dialogs/NewNSTreatmentDialog.java | 13 +++------- .../plugins/DanaR/DanaRFragment.java | 8 +++--- .../DanaR/History/DanaRHistoryActivity.java | 8 +++--- .../plugins/DanaR/comm/MsgHistoryAll.java | 5 ++-- .../DanaRKorean/DanaRKoreanFragment.java | 5 ++-- .../History/DanaRHistoryActivity.java | 8 +++--- .../Dialogs/EditQuickWizardDialog.java | 6 ++--- .../plugins/Overview/OverviewFragment.java | 7 +++-- .../activities/QuickWizardListActivity.java | 9 +++---- .../DataPointWithLabelInterface.java | 2 +- .../PointsWithLabelGraphSeries.java | 3 +-- .../TimeAsXAxisLabelFormatter.java | 2 +- .../SmsCommunicatorFragment.java | 7 +++-- .../TempBasals/TempBasalsFragment.java | 8 +++--- .../Treatments/TreatmentsFragment.java | 5 ++-- .../java/info/nightscout/utils/DateUtil.java | 26 +++++++++++++++++++ .../info/nightscout/utils/TimeListEdit.java | 8 ++---- 19 files changed, 68 insertions(+), 73 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/Overview/{GraphSeriesExtension => graphExtensions}/DataPointWithLabelInterface.java (95%) rename app/src/main/java/info/nightscout/androidaps/plugins/Overview/{GraphSeriesExtension => graphExtensions}/PointsWithLabelGraphSeries.java (98%) rename app/src/main/java/info/nightscout/androidaps/plugins/Overview/{ => graphExtensions}/TimeAsXAxisLabelFormatter.java (92%) diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index 835fec8a59..649ada3738 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -6,14 +6,13 @@ import com.j256.ormlite.table.DatabaseTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Date; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPBASALS) @@ -190,16 +189,15 @@ public class TempBasal { } public String toString() { - DateFormat formatDateToJustTime = new SimpleDateFormat("HH:mm"); String extended = isExtended ? "E " : ""; if (isAbsolute) { return extended + DecimalFormatter.to2Decimal(absolute) + "U/h @" + - formatDateToJustTime.format(timeStart) + + DateUtil.timeString(timeStart) + " " + getRealDuration() + "/" + duration + "min"; } else { // percent return percent + "% @" + - formatDateToJustTime.format(timeStart) + + DateUtil.timeString(timeStart) + " " + getRealDuration() + "/" + duration + "min"; } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java index f7a40284d6..f8c2f3b829 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -13,9 +13,8 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.Iob; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index 43b383f33a..b941cdb4c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -33,7 +33,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; @@ -197,10 +196,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick eventTime = new Date(); dateButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventdate); timeButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventtime); - DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); - DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT); - dateButton.setText(df.format(eventTime)); - timeButton.setText(tf.format(eventTime)); + dateButton.setText(DateUtil.dateString(eventTime)); + timeButton.setText(DateUtil.timeString(eventTime)); dateButton.setOnClickListener(this); timeButton.setOnClickListener(this); @@ -330,8 +327,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick eventTime.setYear(year - 1900); eventTime.setMonth(monthOfYear); eventTime.setDate(dayOfMonth); - DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); - dateButton.setText(df.format(eventTime)); + dateButton.setText(DateUtil.dateString(eventTime)); } @Override @@ -339,8 +335,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick eventTime.setHours(hourOfDay); eventTime.setMinutes(minute); eventTime.setSeconds(second); - DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT); - timeButton.setText(tf.format(eventTime)); + timeButton.setText(DateUtil.timeString(eventTime)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java index 63186fc4db..b7fae2a125 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java @@ -20,7 +20,6 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.util.Date; import info.nightscout.androidaps.MainApp; @@ -32,6 +31,7 @@ import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog; import info.nightscout.androidaps.plugins.DanaR.History.DanaRHistoryActivity; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SetWarnColor; @@ -188,8 +188,6 @@ public class DanaRFragment extends Fragment implements FragmentBase { // GUI functions private void updateGUI() { - final DateFormat formatTime = DateFormat.getTimeInstance(DateFormat.SHORT); - Activity activity = getActivity(); if (activity != null && basaBasalRateView != null) activity.runOnUiThread(new Runnable() { @@ -200,14 +198,14 @@ public class DanaRFragment extends Fragment implements FragmentBase { if (DanaRPlugin.getDanaRPump().lastConnection.getTime() != 0) { Long agoMsec = new Date().getTime() - DanaRPlugin.getDanaRPump().lastConnection.getTime(); int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(formatTime.format(DanaRPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); + lastConnectionView.setText(DateUtil.timeString(DanaRPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); } if (DanaRPlugin.getDanaRPump().lastBolusTime.getTime() != 0) { Long agoMsec = new Date().getTime() - DanaRPlugin.getDanaRPump().lastBolusTime.getTime(); double agoHours = agoMsec / 60d / 60d / 1000d; if (agoHours < 6) // max 6h back - lastBolusView.setText(formatTime.format(DanaRPlugin.getDanaRPump().lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); + lastBolusView.setText(DateUtil.timeString(DanaRPlugin.getDanaRPump().lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); else lastBolusView.setText(""); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java index 1fe6acf43d..902694e1b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java @@ -31,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.SQLException; -import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -46,6 +45,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.ToastUtils; @@ -274,9 +274,8 @@ public class DanaRHistoryActivity extends Activity { @Override public void onBindViewHolder(HistoryViewHolder holder, int position) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DanaRHistoryRecord record = historyList.get(position); - holder.time.setText(df.format(new Date(record.getRecordDate()))); + holder.time.setText(DateUtil.dateAndTimeString(record.getRecordDate())); holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue())); holder.stringvalue.setText(record.getStringRecordValue()); holder.bolustype.setText(record.getBolusType()); @@ -306,11 +305,10 @@ public class DanaRHistoryActivity extends Activity { holder.alarm.setVisibility(View.GONE); break; case RecordTypes.RECORD_TYPE_DAILY: - df = DateFormat.getDateInstance(DateFormat.SHORT); holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U"); holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U"); holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()+ record.getRecordDailyBasal()) + "U"); - holder.time.setText(df.format(new Date(record.getRecordDate()))); + holder.time.setText(DateUtil.timeString(record.getRecordDate())); holder.time.setVisibility(View.VISIBLE); holder.value.setVisibility(View.GONE); holder.stringvalue.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgHistoryAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgHistoryAll.java index 13e1b48cd2..c00f7f6c8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgHistoryAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgHistoryAll.java @@ -6,12 +6,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.SQLException; -import java.text.DateFormat; import java.util.Date; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; +import info.nightscout.utils.DateUtil; public class MsgHistoryAll extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgHistoryAll.class); @@ -150,8 +150,7 @@ public class MsgHistoryAll extends MessageBase { log.error(e.getMessage(), e); } - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - ev.message = df.format(new Date(danaRHistoryRecord.getRecordDate())); + ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.getRecordDate()); ev.message += " " + messageType; MainApp.bus().post(ev); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java index 94beeea1f3..a65fd9a30a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java @@ -20,7 +20,6 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.util.Date; import info.nightscout.androidaps.MainApp; @@ -32,6 +31,7 @@ import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.DanaRKorean.History.DanaRHistoryActivity; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SetWarnColor; @@ -185,7 +185,6 @@ public class DanaRKoreanFragment extends Fragment implements FragmentBase { // GUI functions private void updateGUI() { - final DateFormat formatTime = DateFormat.getTimeInstance(DateFormat.SHORT); Activity activity = getActivity(); if (activity != null && basaBasalRateView != null) @@ -197,7 +196,7 @@ public class DanaRKoreanFragment extends Fragment implements FragmentBase { if (DanaRKoreanPlugin.getDanaRPump().lastConnection.getTime() != 0) { Long agoMsec = new Date().getTime() - DanaRKoreanPlugin.getDanaRPump().lastConnection.getTime(); int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(formatTime.format(DanaRKoreanPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); + lastConnectionView.setText(DateUtil.dateString(DanaRKoreanPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); } // if (DanaRKoreanPlugin.getDanaRPump().lastBolusTime.getTime() != 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRHistoryActivity.java index 1b2f8165cf..d23cff488b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRHistoryActivity.java @@ -31,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.SQLException; -import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -47,6 +46,7 @@ import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatu import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.ToastUtils; @@ -273,9 +273,8 @@ public class DanaRHistoryActivity extends Activity { @Override public void onBindViewHolder(HistoryViewHolder holder, int position) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DanaRHistoryRecord record = historyList.get(position); - holder.time.setText(df.format(new Date(record.getRecordDate()))); + holder.time.setText(DateUtil.dateAndTimeString(record.getRecordDate())); holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue())); holder.stringvalue.setText(record.getStringRecordValue()); holder.bolustype.setText(record.getBolusType()); @@ -305,11 +304,10 @@ public class DanaRHistoryActivity extends Activity { holder.alarm.setVisibility(View.GONE); break; case RecordTypes.RECORD_TYPE_DAILY: - df = DateFormat.getDateInstance(DateFormat.SHORT); holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U"); holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U"); holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()+ record.getRecordDailyBasal()) + "U"); - holder.time.setText(df.format(new Date(record.getRecordDate()))); + holder.time.setText(DateUtil.dateString(record.getRecordDate())); holder.time.setVisibility(View.VISIBLE); holder.value.setVisibility(View.GONE); holder.stringvalue.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java index 4cc94432d5..a86740cdfd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java @@ -15,7 +15,6 @@ import android.widget.Spinner; import org.json.JSONException; -import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -62,15 +61,14 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic int posFrom = 0; int posTo = 95; ArrayList timeList = new ArrayList<>(); - DateFormat df = new SimpleDateFormat("HH:mm"); int pos = 0; for (int t = 0; t < 24 * 60 * 60; t += 15 * 60) { - timeList.add(df.format(DateUtil.toDate(t))); + timeList.add(DateUtil.timeString(DateUtil.toDate(t))); if (entry.validFrom() == t) posFrom = pos; if (entry.validTo() == t) posTo = pos; pos++; } - timeList.add(df.format(DateUtil.toDate(24 * 60 * 60 - 60))); + timeList.add(DateUtil.timeString(DateUtil.toDate(24 * 60 * 60 - 60))); ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, timeList); 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 5cfd090a0c..1cb7ae9b59 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 @@ -38,7 +38,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; @@ -73,9 +72,10 @@ import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; -import info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; @@ -822,11 +822,10 @@ public class OverviewFragment extends Fragment { @Override public void onBindViewHolder(NotificationsViewHolder holder, int position) { - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); Notification notification = notificationsList.get(position); holder.dismiss.setTag(notification); holder.text.setText(notification.text); - holder.time.setText(df.format(notification.date)); + holder.time.setText(DateUtil.timeString(notification.date)); if (notification.level == Notification.URGENT) holder.cv.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationUrgent)); else if (notification.level == Notification.NORMAL) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java index dafd0766d1..ef2ebe240c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java @@ -15,17 +15,15 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import java.text.DateFormat; import java.text.SimpleDateFormat; -import info.nightscout.androidaps.AgreementActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.QuickWizard; import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange; -import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; public class QuickWizardListActivity extends AppCompatActivity implements View.OnClickListener { @@ -54,9 +52,8 @@ public class QuickWizardListActivity extends AppCompatActivity implements View.O @Override public void onBindViewHolder(QuickWizardEntryViewHolder holder, int position) { - DateFormat df = new SimpleDateFormat("HH:mm"); - holder.from.setText(df.format(qvData.get(position).validFromDate())); - holder.to.setText(df.format(qvData.get(position).validToDate())); + holder.from.setText(DateUtil.timeString(qvData.get(position).validFromDate())); + holder.to.setText(DateUtil.timeString(qvData.get(position).validToDate())); holder.buttonText.setText(qvData.get(position).buttonText()); holder.carbs.setText(DecimalFormatter.to0Decimal(qvData.get(position).carbs()) + " g"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/DataPointWithLabelInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/DataPointWithLabelInterface.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java index af6c61272c..1c02eb66d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/DataPointWithLabelInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension; +package info.nightscout.androidaps.plugins.Overview.graphExtensions; /** * GraphView * Copyright (C) 2014 Jonas Gehring diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/PointsWithLabelGraphSeries.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java index 44c07ef6c8..7671813090 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/GraphSeriesExtension/PointsWithLabelGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension; +package info.nightscout.androidaps.plugins.Overview.graphExtensions; /** * GraphView @@ -25,7 +25,6 @@ package info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension; */ import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Point; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/TimeAsXAxisLabelFormatter.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/TimeAsXAxisLabelFormatter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java index f108c631e1..c8ba40369d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/TimeAsXAxisLabelFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview; +package info.nightscout.androidaps.plugins.Overview.graphExtensions; import android.content.Context; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java index 852562ddda..83973e83ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java @@ -15,13 +15,13 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.util.Collections; import java.util.Comparator; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui; +import info.nightscout.utils.DateUtil; /** * A simple {@link Fragment} subclass. @@ -89,15 +89,14 @@ public class SmsCommunicatorFragment extends Fragment { int messagesToShow = 40; int start = Math.max(0, getPlugin().messages.size() - messagesToShow); - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); String logText = ""; for (int x = start; x < getPlugin().messages.size(); x++) { SmsCommunicatorPlugin.Sms sms = getPlugin().messages.get(x); if (sms.received) { - logText += df.format(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; + logText += DateUtil.timeString(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; } else if (sms.sent) { - logText += df.format(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; + logText += DateUtil.timeString(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; } } logView.setText(Html.fromHtml(logText)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java index f194c3a53a..f661cc4a5b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java @@ -17,7 +17,6 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.util.Date; import java.util.List; @@ -27,6 +26,7 @@ import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -61,13 +61,11 @@ public class TempBasalsFragment extends Fragment implements FragmentBase { @Override public void onBindViewHolder(TempBasalsViewHolder holder, int position) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); - DateFormat enddf = DateFormat.getTimeInstance(DateFormat.SHORT); TempBasal tempBasal = tempBasalList.get(position); if (tempBasal.timeEnd != null) { - holder.date.setText(df.format(tempBasal.timeStart) + " - " + enddf.format(tempBasalList.get(position).timeEnd)); + holder.date.setText(DateUtil.dateAndTimeString(tempBasal.timeStart) + " - " + DateUtil.timeString(tempBasalList.get(position).timeEnd)); } else { - holder.date.setText(df.format(tempBasal.timeStart)); + holder.date.setText(DateUtil.dateAndTimeString(tempBasal.timeStart)); } holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.duration) + " min"); if (tempBasal.isAbsolute) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index 0c36451573..818d33f245 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -23,7 +23,6 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.util.Date; import java.util.List; @@ -35,6 +34,7 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.ToastUtils; @@ -76,8 +76,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); if (profile == null) return; - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); - holder.date.setText(df.format(treatments.get(position).created_at)); + holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at)); holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U"); holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g"); Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia()); diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index fb12986b7d..4ad75f7d06 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -1,5 +1,7 @@ package info.nightscout.utils; +import android.text.format.DateUtils; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -9,6 +11,8 @@ import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; +import info.nightscout.androidaps.MainApp; + /** * The Class DateUtil. A simple wrapper around SimpleDateFormat to ease the handling of iso date string <-> date obj * with TZ @@ -81,4 +85,26 @@ public class DateUtil { return retval; } + public static String dateString(Date date) { + return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_DATE); + } + + public static String dateString(long mills) { + return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_DATE); + } + + public static String timeString(Date date) { + return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_TIME); + } + + public static String timeString(long mills) { + return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_TIME); + } + + public static String dateAndTimeString(Date date) { + return dateString(date) + " " + timeString(date); + } + public static String dateAndTimeString(long mills) { + return dateString(mills) + " " + timeString(mills); + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index f3975e3e7a..811bec61fe 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -23,9 +23,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; import java.text.NumberFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; import info.nightscout.androidaps.MainApp; @@ -224,10 +222,9 @@ public class TimeListEdit { public void fillSpinner(Spinner spinner, int secondsFromMidnight, int previous, int next) { int posInList = 0; ArrayList timeList = new ArrayList<>(); - DateFormat df = new SimpleDateFormat("HH:mm"); int pos = 0; for (int t = previous + ONEHOURINSECONDS; t < next; t += ONEHOURINSECONDS) { - timeList.add(df.format(DateUtil.toDate(t))); + timeList.add(DateUtil.timeString(DateUtil.toDate(t))); if (secondsFromMidnight == t) posInList = pos; pos++; } @@ -332,10 +329,9 @@ public class TimeListEdit { } void log() { - DateFormat df = new SimpleDateFormat("HH:mm"); for (int i = 0; i < data1.length(); i++) { int pos = 0; - log.debug(i + ": @" + df.format(DateUtil.toDate(secondFromMidnight(i))) + " " + value1(i) + (data2 != null ? " " + value2(i) : "")); + log.debug(i + ": @" + DateUtil.timeString(DateUtil.toDate(secondFromMidnight(i))) + " " + value1(i) + (data2 != null ? " " + value2(i) : "")); } } } From 6dc3d38a2f45ef7448ad21f7893e344d1629ddcf Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 6 Jan 2017 09:52:17 +0100 Subject: [PATCH 11/15] fix passing carb ratio --- .../androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java index ca62b7a197..a695e6a866 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java @@ -111,7 +111,7 @@ public class DetermineBasalAdapterJS implements Parcelable { mProfile.add("max_basal", 0); mProfile.add("max_bg", 0); mProfile.add("min_bg", 0); - mProfile.add("carbratio", 0); + mProfile.add("carb_ratio", 0); mProfile.add("sens", 0); mProfile.add("current_basal", 0); mV8rt.add(PARAM_profile, mProfile); @@ -280,7 +280,7 @@ public class DetermineBasalAdapterJS implements Parcelable { mProfile.add("min_bg", minBg); mProfile.add("max_bg", maxBg); mProfile.add("target_bg", targetBg); - mProfile.add("carbratio", profile.getIc(profile.secondsFromMidnight())); + mProfile.add("carb_ratio", profile.getIc(profile.secondsFromMidnight())); mProfile.add("sens", NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()).doubleValue(), units)); mProfile.add("current_basal", pump.getBaseBasalRate()); From 38f397cd592fc24cf989b5aab5f36f4b14f1bcd1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 7 Jan 2017 23:26:28 +0100 Subject: [PATCH 12/15] revert formating date --- .../plugins/DanaR/History/DanaRHistoryActivity.java | 2 +- .../plugins/DanaRKorean/DanaRKoreanFragment.java | 2 +- app/src/main/java/info/nightscout/utils/DateUtil.java | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java index 902694e1b7..4056943e70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRHistoryActivity.java @@ -308,7 +308,7 @@ public class DanaRHistoryActivity extends Activity { holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U"); holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U"); holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()+ record.getRecordDailyBasal()) + "U"); - holder.time.setText(DateUtil.timeString(record.getRecordDate())); + holder.time.setText(DateUtil.dateString(record.getRecordDate())); holder.time.setVisibility(View.VISIBLE); holder.value.setVisibility(View.GONE); holder.stringvalue.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java index a65fd9a30a..907718f636 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java @@ -196,7 +196,7 @@ public class DanaRKoreanFragment extends Fragment implements FragmentBase { if (DanaRKoreanPlugin.getDanaRPump().lastConnection.getTime() != 0) { Long agoMsec = new Date().getTime() - DanaRKoreanPlugin.getDanaRPump().lastConnection.getTime(); int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(DateUtil.dateString(DanaRKoreanPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); + lastConnectionView.setText(DateUtil.timeString(DanaRKoreanPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); } // if (DanaRKoreanPlugin.getDanaRPump().lastBolusTime.getTime() != 0) { diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index 4ad75f7d06..c4efa45f93 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -86,11 +86,15 @@ public class DateUtil { } public static String dateString(Date date) { - return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_DATE); + //return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_DATE); this provide month name not number + DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); + return df.format(date); } public static String dateString(long mills) { - return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_DATE); + //return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_DATE); this provide month name not number + DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); + return df.format(mills); } public static String timeString(Date date) { From 75192f0372880d1baec86b58384eba17966a6111 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 7 Jan 2017 23:38:59 +0100 Subject: [PATCH 13/15] prevent logging exception --- .../persistentnotification/PersistentNotificationPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java index dffe461ead..653bc6e7b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java @@ -176,7 +176,9 @@ public class PersistentNotificationPlugin implements PluginBase{ if(fragmentEnabled){ MainApp.bus().register(this); } else { - MainApp.bus().unregister(this); + try { + MainApp.bus().unregister(this); + } catch (Exception e) {} } } From f704090eac914afd5cbab1fb0fa865fdb9a34e6a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 7 Jan 2017 23:39:29 +0100 Subject: [PATCH 14/15] version bump 1.1 --- .idea/misc.xml | 2 +- app/build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981032..fbb68289f4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index da35bd40a7..9740cf7335 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,8 +43,8 @@ android { applicationId "info.nightscout.androidaps" minSdkVersion 21 targetSdkVersion 23 - versionCode 1020 - versionName "1.0.20" + versionCode 1100 + versionName "1.1" buildConfigField "String", "BUILDVERSION", generateGitBuild() } lintOptions { From 7b5a289fc1109439b08bfe55c63185dc3321258e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 8 Jan 2017 00:45:43 +0100 Subject: [PATCH 15/15] run aps only on interested treatments --- .../info/nightscout/androidaps/Services/DataService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 734e3defaf..7ba381f130 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -346,7 +346,6 @@ public class DataService extends IntentService { handleAddedTreatment(trstr); } } - scheduleTreatmentChange(); } catch (Exception e) { e.printStackTrace(); } @@ -368,7 +367,6 @@ public class DataService extends IntentService { handleChangedTreatment(trstr); } } - scheduleTreatmentChange(); } catch (Exception e) { e.printStackTrace(); } @@ -392,7 +390,6 @@ public class DataService extends IntentService { removeTreatmentFromDb(_id); } } - scheduleTreatmentChange(); } catch (Exception e) { e.printStackTrace(); } @@ -471,6 +468,7 @@ public class DataService extends IntentService { int updated = MainApp.getDbHelper().getDaoTreatments().update(stored); if (Config.logIncommingData) log.debug("Records updated: " + updated); + scheduleTreatmentChange(); } } else { if (Config.logIncommingData) @@ -494,6 +492,7 @@ public class DataService extends IntentService { } catch (SQLException e) { e.printStackTrace(); } + scheduleTreatmentChange(); } } @@ -547,6 +546,7 @@ public class DataService extends IntentService { } catch (SQLException e) { e.printStackTrace(); } + scheduleTreatmentChange(); } public void handleDanaRHistoryRecords(JSONObject trJson) throws JSONException, SQLException {