boluses working

This commit is contained in:
Milos Kozak 2017-05-22 22:10:56 +02:00
parent 6cd046459a
commit 6394421017
12 changed files with 62 additions and 64 deletions

View file

@ -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);
}

View file

@ -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 +

View file

@ -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;

View file

@ -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());

View file

@ -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();

View file

@ -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);

View file

@ -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">
<LinearLayout
android:layout_width="match_parent"
@ -22,14 +22,15 @@
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="@string/treatments_iobtotal_label_string"
android:textStyle="bold" />
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/treatments_iobtotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
android:id="@+id/treatments_iobactivitytotal_label"
@ -37,14 +38,15 @@
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="@string/treatments_iobactivitytotal_label_string"
android:textStyle="bold" />
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/treatments_iobactivitytotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
</LinearLayout>

View file

@ -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">
<LinearLayout
android:layout_width="match_parent"
@ -16,7 +13,6 @@
android:orientation="vertical">
<LinearLayout
android:id="@+id/treatments_datelinearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
@ -28,29 +24,22 @@
android:layout_gravity="center_vertical"
android:gravity="center_vertical|right"
android:paddingLeft="10dp"
android:text="{fa-clock-o}"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/cardItemLabel" />
android:text="{fa-clock-o}" />
<TextView
android:id="@+id/treatments_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/cardItemLabel"
android:textStyle="bold" />
android:paddingLeft="5dp" />
<TextView
android:text="Meal"
android:id="@+id/treatments_mealorcorrection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_mealorcorrection"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textAlignment="textEnd"
android:textColor="@color/mdtp_red"
android:layout_marginRight="5dp" />
android:text="Meal"
android:textAlignment="textEnd" />
</LinearLayout>
@ -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 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -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" />
<TextView
android:id="@+id/treatments_tempbasals"

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment">
tools:context="info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsTemporaryBasalsFragment">
<LinearLayout
android:layout_width="match_parent"

View file

@ -5,8 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardBackgroundColor="?android:colorBackground"
>
card_view:cardBackgroundColor="?android:colorBackground">
<LinearLayout
android:layout_width="match_parent"
@ -162,9 +161,9 @@
android:id="@+id/tempbasals_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:layout_marginRight="10dp"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
@ -180,7 +179,6 @@
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -32,7 +32,7 @@
<string name="treatments_iob_label_string">IOB:</string>
<string name="sms_iob">IOB:</string>
<string name="treatments_activity_string">Activity:</string>
<string name="treatments_iobtotal_label_string">Toal IOB:</string>
<string name="treatments_iobtotal_label_string">Total IOB:</string>
<string name="treatments_iobactivitytotal_label_string">Total IOB activity:</string>
<string name="tempbasals_realduration_label_string">Dur:</string>
<string name="tempbasals_netratio_label_string">Ratio:</string>