From 63944210175459474049e8dc072207953ddc8996 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 22 May 2017 22:10:56 +0200 Subject: [PATCH] boluses working --- .../androidaps/db/DatabaseHelper.java | 22 +++++++----- .../nightscout/androidaps/db/Treatment.java | 2 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 16 ++------- .../PumpVirtual/VirtualPumpPlugin.java | 1 - .../fragments/TreatmentsBolusFragment.java | 15 ++++---- .../TreatmentsTemporaryBasalsFragment.java | 10 +++--- .../res/layout/treatments_bolus_fragment.xml | 12 ++++--- ...nts_item.xml => treatments_bolus_item.xml} | 36 +++++++++---------- .../main/res/layout/treatments_fragment.xml | 2 +- ...xml => treatments_tempbasals_fragment.xml} | 2 +- ...tem.xml => treatments_tempbasals_item.xml} | 6 ++-- app/src/main/res/values/strings.xml | 2 +- 12 files changed, 62 insertions(+), 64 deletions(-) rename app/src/main/res/layout/{treatments_item.xml => treatments_bolus_item.xml} (85%) rename app/src/main/res/layout/{tempbasals_fragment.xml => treatments_tempbasals_fragment.xml} (96%) rename app/src/main/res/layout/{tempbasals_item.xml => treatments_tempbasals_item.xml} (99%) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 9248c17dfa..ba21ce4d2d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -377,7 +377,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // -------------------- TREATMENT HANDLING ------------------- - public boolean affectingIobCob(Treatment t) { + public boolean changeAffectingIobCob(Treatment t) { Treatment existing = findTreatmentByTimeIndex(t.date); if (existing == null) return true; @@ -387,9 +387,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } public int update(Treatment treatment) { + treatment.date = treatment.date - treatment.date % 1000; int updated = 0; try { - boolean historyChange = affectingIobCob(treatment); + boolean historyChange = changeAffectingIobCob(treatment); updated = getDaoTreatments().update(treatment); if (historyChange) latestTreatmentChange = treatment.date; @@ -401,9 +402,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } public Dao.CreateOrUpdateStatus createOrUpdate(Treatment treatment) { + treatment.date = treatment.date - treatment.date % 1000; Dao.CreateOrUpdateStatus status = null; try { - boolean historyChange = affectingIobCob(treatment); + boolean historyChange = changeAffectingIobCob(treatment); status = getDaoTreatments().createOrUpdate(treatment); if (historyChange) latestTreatmentChange = treatment.date; @@ -415,6 +417,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } public void create(Treatment treatment) { + treatment.date = treatment.date - treatment.date % 1000; try { getDaoTreatments().create(treatment); latestTreatmentChange = treatment.date; @@ -511,12 +514,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduledTratmentPost = null; } } - // prepare task for execution in 5 sec + // prepare task for execution in 1 sec // cancel waiting task to prevent sending multiple posts if (scheduledTratmentPost != null) scheduledTratmentPost.cancel(false); Runnable task = new PostRunnable(); - final int sec = 5; + final int sec = 1; scheduledTratmentPost = treatmentsWorker.schedule(task, sec, TimeUnit.SECONDS); } @@ -708,6 +711,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } public void create(TemporaryBasal tempBasal) { + tempBasal.date = tempBasal.date - tempBasal.date % 1000; try { getDaoTemporaryBasal().create(tempBasal); latestTreatmentChange = tempBasal.date; @@ -750,12 +754,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduledTemBasalsPost = null; } } - // prepare task for execution in 5 sec + // prepare task for execution in 1 sec // cancel waiting task to prevent sending multiple posts if (scheduledTemBasalsPost != null) scheduledTemBasalsPost.cancel(false); Runnable task = new PostRunnable(); - final int sec = 5; + final int sec = 1; scheduledTemBasalsPost = tempBasalsWorker.schedule(task, sec, TimeUnit.SECONDS); } @@ -817,12 +821,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduledExtendedBolusPost = null; } } - // prepare task for execution in 5 sec + // prepare task for execution in 1 sec // cancel waiting task to prevent sending multiple posts if (scheduledExtendedBolusPost != null) scheduledExtendedBolusPost.cancel(false); Runnable task = new PostRunnable(); - final int sec = 5; + final int sec = 1; scheduledExtendedBolusPost = extendedBolusWorker.schedule(task, sec, TimeUnit.SECONDS); } 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 1b52fde682..5b86b1f483 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -73,7 +73,7 @@ public class Treatment implements DataPointWithLabelInterface { public String log() { return "Treatment{" + "date= " + date + - "date= " + DateUtil.dateAndTimeString(date) + + ", date= " + DateUtil.dateAndTimeString(date) + ", isValid= " + isValid + ", _id= " + _id + ", insulin= " + insulin + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 11c135e59b..a2c827c4da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -504,25 +504,15 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain Treatment t = new Treatment(insulinType); t.insulin = result.bolusDelivered; t.carbs = (double) result.carbsDelivered; - t.date = new Date().getDate(); + t.date = new Date().getTime(); t.mealBolus = t.carbs > 0; MainApp.getDbHelper().create(t); t.sendToNSClient(); } } else { - if (Config.logCongigBuilderActions) - log.debug("Creating treatment: " + insulin + " carbs: " + carbs); - Treatment t = new Treatment(insulinType); - t.insulin = insulin; - t.carbs = (double) carbs; - t.date = new Date().getDate(); - t.mealBolus = t.carbs > 0; - MainApp.getDbHelper().create(t); - t.sendToNSClient(); + log.error("activePump==null"); result = new PumpEnactResult(); - result.success = true; - result.bolusDelivered = insulin; - result.carbsDelivered = carbs; + result.success = false; } mWakeLock.release(); return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index e1907122e7..1e22aa7ebc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -221,7 +221,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { Thread.sleep(1000); } catch (InterruptedException e) { } - if (Config.logPumpComm) log.debug("Delivering treatment insulin: " + insulin + "U carbs: " + carbs + "g " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsBolusFragment.java index 8cb498a8c4..045e8091e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsBolusFragment.java @@ -16,7 +16,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.LinearLayout; import android.widget.TextView; import com.crashlytics.android.answers.Answers; @@ -34,6 +33,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; @@ -65,7 +65,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis @Override public TreatmentsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_item, viewGroup, false); + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_bolus_item, viewGroup, false); return new TreatmentsViewHolder(v); } @@ -84,9 +84,9 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U"); holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous)); if (iob.iobContrib != 0) - holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); + holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); else - holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground)); + holder.iob.setTextColor(holder.carbs.getCurrentTextColor()); holder.remove.setTag(treatments.get(position)); } @@ -108,7 +108,6 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis TextView iob; TextView activity; TextView mealOrCorrection; - LinearLayout dateLinearLayout; TextView remove; TreatmentsViewHolder(View itemView) { @@ -120,7 +119,6 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis iob = (TextView) itemView.findViewById(R.id.treatments_iob); activity = (TextView) itemView.findViewById(R.id.treatments_activity); mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection); - dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout); remove = (TextView) itemView.findViewById(R.id.treatments_remove); remove.setOnClickListener(this); remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); @@ -221,6 +219,11 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis updateGUI(); } + @Subscribe + public void onStatusEvent(final EventNewBG ev) { + updateGUI(); + } + public void updateGUI() { Activity activity = getActivity(); NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsTemporaryBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsTemporaryBasalsFragment.java index 654cba6b89..6acc0ad1c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsTemporaryBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/fragments/TreatmentsTemporaryBasalsFragment.java @@ -14,7 +14,6 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import android.widget.TextView; import com.crashlytics.android.answers.Answers; @@ -32,7 +31,6 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; -import info.nightscout.androidaps.plugins.TreatmentsFromHistory.TreatmentsFromHistoryPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.OverlappingIntervals; @@ -58,7 +56,7 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment { @Override public TempBasalsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tempbasals_item, viewGroup, false); + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_tempbasals_item, viewGroup, false); return new TempBasalsViewHolder(v); } @@ -87,8 +85,12 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment { holder.extendedFlag.setVisibility(View.GONE); if (tempBasal.isInProgress()) holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); + else + holder.date.setTextColor(holder.netRatio.getCurrentTextColor()); if (tempBasal.iobCalc(new Date().getTime()).basaliob != 0) holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); + else + holder.date.setTextColor(holder.netRatio.getCurrentTextColor()); holder.remove.setTag(tempBasal); } @@ -162,7 +164,7 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.tempbasals_fragment, container, false); + View view = inflater.inflate(R.layout.treatments_tempbasals_fragment, container, false); recyclerView = (RecyclerView) view.findViewById(R.id.tempbasals_recyclerview); recyclerView.setHasFixedSize(true); diff --git a/app/src/main/res/layout/treatments_bolus_fragment.xml b/app/src/main/res/layout/treatments_bolus_fragment.xml index ae7191a5dd..d57ac3daeb 100644 --- a/app/src/main/res/layout/treatments_bolus_fragment.xml +++ b/app/src/main/res/layout/treatments_bolus_fragment.xml @@ -2,7 +2,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".plugins.Treatments.fragments.TreatmentsBolusFragment"> + tools:context=".plugins.TreatmentsFromHistory.fragments.TreatmentsBolusFragment"> + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textAppearance="?android:attr/textAppearanceSmall" + android:textStyle="bold" /> + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textAppearance="?android:attr/textAppearanceSmall" + android:textStyle="bold" /> diff --git a/app/src/main/res/layout/treatments_item.xml b/app/src/main/res/layout/treatments_bolus_item.xml similarity index 85% rename from app/src/main/res/layout/treatments_item.xml rename to app/src/main/res/layout/treatments_bolus_item.xml index f1eec9c048..d2a30aa0aa 100644 --- a/app/src/main/res/layout/treatments_item.xml +++ b/app/src/main/res/layout/treatments_bolus_item.xml @@ -5,10 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" - card_view:cardBackgroundColor="@color/cardColorBackground" - card_view:cardCornerRadius="6dp" - card_view:cardUseCompatPadding="true" - card_view:contentPadding="6dp"> + card_view:cardBackgroundColor="?android:colorBackground"> + android:text="{fa-clock-o}" /> + android:paddingLeft="5dp" /> + android:text="Meal" + android:textAlignment="textEnd" /> @@ -138,6 +127,7 @@ android:id="@+id/treatments_remove" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="10dp" android:layout_weight="1" android:text="@string/overview_quickwizard_item_remove_button" android:textAlignment="viewEnd" @@ -145,6 +135,16 @@ + + diff --git a/app/src/main/res/layout/treatments_fragment.xml b/app/src/main/res/layout/treatments_fragment.xml index bcc7dd9725..55a0944291 100644 --- a/app/src/main/res/layout/treatments_fragment.xml +++ b/app/src/main/res/layout/treatments_fragment.xml @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_horizontal" - android:text="@string/treatments" /> + android:text="@string/bolus" /> + tools:context="info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsTemporaryBasalsFragment"> + card_view:cardBackgroundColor="?android:colorBackground"> @@ -180,7 +179,6 @@ android:layout_marginTop="5dp" android:background="@color/listdelimiter" /> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b6b76a215..4ed13b20b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,7 +32,7 @@ IOB: IOB: Activity: - Toal IOB: + Total IOB: Total IOB activity: Dur: Ratio: