fixing bugs after refactoring

This commit is contained in:
Milos Kozak 2016-08-07 23:21:08 +02:00
parent 12b014afd4
commit 294f9d6c99
13 changed files with 150 additions and 164 deletions

View file

@ -107,10 +107,10 @@ public class DataService extends IntentService {
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) { } else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
handleNewSMS(intent); handleNewSMS(intent);
} }
DataReceiver.completeWakefulIntent(intent);
} }
if (Config.logFunctionCalls) if (Config.logFunctionCalls)
log.debug("onHandleIntent exit"); log.debug("onHandleIntent exit " + intent);
DataReceiver.completeWakefulIntent(intent);
} }
/* /*

View file

@ -28,9 +28,6 @@ import java.util.List;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
@ -240,6 +237,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
dest.writeDouble(delta); dest.writeDouble(delta);
dest.writeDouble(glucose); dest.writeDouble(glucose);
} }
public final Parcelable.Creator<GlucoseStatus> CREATOR = new Parcelable.Creator<GlucoseStatus>() { public final Parcelable.Creator<GlucoseStatus> CREATOR = new Parcelable.Creator<GlucoseStatus>() {
public GlucoseStatus createFromParcel(Parcel in) { public GlucoseStatus createFromParcel(Parcel in) {
return new GlucoseStatus(in); return new GlucoseStatus(in);
@ -256,7 +254,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
glucose = in.readDouble(); glucose = in.readDouble();
} }
public GlucoseStatus() {} public GlucoseStatus() {
}
public GlucoseStatus(Double glucose, Double delta, Double avgdelta) { public GlucoseStatus(Double glucose, Double delta, Double avgdelta) {
this.glucose = glucose; this.glucose = glucose;

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 25.06.2016.
*/
public class EventRefreshOpenLoop {
}

View file

@ -655,6 +655,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
@Subscribe @Subscribe
public void onStatusEvent(final EventNewBG ev) { public void onStatusEvent(final EventNewBG ev) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Give some time to Loop // Give some time to Loop
try { try {
Thread.sleep(120 * 1000L); Thread.sleep(120 * 1000L);
@ -666,6 +669,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
uploadDeviceStatus(); uploadDeviceStatus();
} }
} }
});
t.start();
}
public void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) { public void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) {
try { try {

View file

@ -12,16 +12,18 @@ import android.support.v7.app.NotificationCompat;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import java.util.ArrayList; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshOpenLoop;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
@ -29,11 +31,14 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class LoopPlugin implements PluginBase { public class LoopPlugin implements PluginBase {
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
private static Handler sHandler; private static Handler sHandler;
private static HandlerThread sHandlerThread; private static HandlerThread sHandlerThread;
@ -112,6 +117,9 @@ public class LoopPlugin implements PluginBase {
} }
public void invoke(boolean allowNotification) { public void invoke(boolean allowNotification) {
try {
if (Config.logFunctionCalls)
log.debug("invoke");
ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder(); ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder();
if (!constraintsInterface.isLoopEnabled()) { if (!constraintsInterface.isLoopEnabled()) {
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled))); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled)));
@ -201,12 +209,16 @@ public class LoopPlugin implements PluginBase {
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on. // mId allows you to update the notification later on.
mNotificationManager.notify(Constants.notificationID, builder.build()); mNotificationManager.notify(Constants.notificationID, builder.build());
MainApp.bus().post(new EventRefreshOpenLoop()); MainApp.bus().post(new EventNewOpenLoopNotification());
} }
} }
MainApp.bus().post(new EventLoopUpdateGui()); MainApp.bus().post(new EventLoopUpdateGui());
MainApp.getConfigBuilder().uploadDeviceStatus(); MainApp.getConfigBuilder().uploadDeviceStatus();
} finally {
if (Config.logFunctionCalls)
log.debug("invoke end");
}
} }
} }

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.plugins.Loop.events;
/**
* Created by mike on 07.08.2016.
*/
public class EventNewOpenLoopNotification {
}

View file

@ -48,11 +48,11 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventRefreshOpenLoop;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
@ -92,8 +92,8 @@ public class OverviewFragment extends Fragment {
Button setExtenedButton; Button setExtenedButton;
Button acceptTempButton; Button acceptTempButton;
private static Handler sLoopHandler = new Handler(); Handler sLoopHandler = new Handler();
private static Runnable sRefreshLoop = null; Runnable sRefreshLoop = null;
private static Handler sHandler; private static Handler sHandler;
private static HandlerThread sHandlerThread; private static HandlerThread sHandlerThread;
@ -114,21 +114,6 @@ public class OverviewFragment extends Fragment {
return new OverviewFragment(); return new OverviewFragment();
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (sRefreshLoop == null) {
sRefreshLoop = new Runnable() {
@Override
public void run() {
updateGUIIfVisible();
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
}
};
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
}
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -217,6 +202,7 @@ public class OverviewFragment extends Fragment {
sHandler.post(new Runnable() { sHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
acceptTempLayout.setVisibility(View.GONE);
PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed); PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed);
if (applyResult.enacted) { if (applyResult.enacted) {
finalLastRun.setByPump = applyResult; finalLastRun.setByPump = applyResult;
@ -249,12 +235,21 @@ public class OverviewFragment extends Fragment {
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
sLoopHandler.removeCallbacksAndMessages(null);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
MainApp.bus().register(this); MainApp.bus().register(this);
sRefreshLoop = new Runnable() {
@Override
public void run() {
updateGUIIfVisible();
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
}
};
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
} }
@Subscribe @Subscribe
@ -283,7 +278,7 @@ public class OverviewFragment extends Fragment {
} }
@Subscribe @Subscribe
public void onStatusEvent(final EventRefreshOpenLoop ev) { public void onStatusEvent(final EventNewOpenLoopNotification ev) {
updateGUIIfVisible(); updateGUIIfVisible();
} }

View file

@ -24,9 +24,9 @@ import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.TempBasals.events.EventTempBasalsUpdateGui;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -163,9 +163,8 @@ public class TempBasalsFragment extends Fragment implements FragmentBase {
MainApp.bus().register(this); MainApp.bus().register(this);
} }
@Subscribe @Subscribe
public void onStatusEvent(final EventTempBasalsUpdateGui s) { public void onStatusEvent(final EventTempBasalChange ev) {
updateGUI(); updateGUI();
} }

View file

@ -29,7 +29,6 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TempBasalsInterface; import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.TempBasals.events.EventTempBasalsUpdateGui;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.plugins.TempBasals.events;
/**
* Created by mike on 05.08.2016.
*/
public class EventTempBasalsUpdateGui {
}

View file

@ -16,17 +16,12 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -37,12 +32,6 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Treatments.events.EventTreatmentsUpdateGui;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -185,10 +174,6 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
MainApp.bus().register(this); MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventTreatmentsUpdateGui ev) {
updateGUI(); updateGUI();
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Treatments;
import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.QueryBuilder;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,10 +17,10 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Treatments.events.EventTreatmentsUpdateGui;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
/** /**
@ -79,7 +80,6 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
public TreatmentsPlugin() { public TreatmentsPlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
initializeData(); initializeData();
MainApp.bus().post(new EventTreatmentsUpdateGui());
} }
public void initializeData() { public void initializeData() {
@ -171,5 +171,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
return treatments; return treatments;
} }
@Subscribe
public void onStatusEvent(final EventTreatmentChange ev) {
initializeData();
updateTotalIOB();
}
} }

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.plugins.Treatments.events;
/**
* Created by mike on 05.08.2016.
*/
public class EventTreatmentsUpdateGui {
}