bind service to application context, adjust messages timing

This commit is contained in:
Milos Kozak 2016-07-18 21:20:53 +02:00
parent 3e3ad1d515
commit 87dd8712b4
3 changed files with 19 additions and 5 deletions

View file

@ -799,7 +799,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
String settingVisible = "ConfigBuilder_" + type + "_" + p.getName() + "_Visible";
if (SP.contains(settingEnabled))
p.setFragmentEnabled(type, SP.getBoolean(settingEnabled, true));
if (SP.contains("ConfigBuilder" + p.getName() + "Visible"))
if (SP.contains(settingVisible))
p.setFragmentVisible(type, SP.getBoolean(settingVisible, true));
}
}

View file

@ -38,6 +38,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
@ -102,6 +103,9 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
this.mHandler = new Handler(mHandlerThread.getLooper());
registerBus();
Context context = MainApp.instance().getApplicationContext();
Intent intent = new Intent(context, ExecutionService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
public static DanaRFragment newInstance() {
@ -184,6 +188,12 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
return view;
}
@Subscribe
public void onStatusEvent(final EventAppExit e) {
MainApp.instance().getApplicationContext().unbindService(mConnection);
}
/*
@Override
public void onStart() {
super.onStart();
@ -191,6 +201,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
Intent intent = new Intent(context, ExecutionService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
*/
ServiceConnection mConnection = new ServiceConnection() {
@ -208,6 +219,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
}
};
/*
@Override
public void onStop() {
super.onStop();
@ -216,8 +228,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
mBounded = false;
}
}
;
*/
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {

View file

@ -108,7 +108,7 @@ public class ExecutionService extends Service {
danaRPump = danaRFragment.getDanaRPump();
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaConnection");
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ExecutionService");
}
public class LocalBinder extends Binder {
@ -141,7 +141,6 @@ public class ExecutionService extends Service {
public void onStatusEvent(EventAppExit event) {
if (Config.logFunctionCalls)
log.debug("EventAppExit received");
// TODO: mDanaConnection.stop();
if (mSerialIOThread != null)
mSerialIOThread.disconnect("Application exit");
@ -295,6 +294,7 @@ public class ExecutionService extends Service {
connect("tempBasal");
if (!isConnected()) return false;
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
waitMsec(200);
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
return true;
}
@ -303,6 +303,7 @@ public class ExecutionService extends Service {
connect("tempBasalStop");
if (!isConnected()) return false;
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
waitMsec(200);
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
return true;
}
@ -311,6 +312,7 @@ public class ExecutionService extends Service {
connect("extendedBolus");
if (!isConnected()) return false;
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
waitMsec(200);
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
return true;
}
@ -319,6 +321,7 @@ public class ExecutionService extends Service {
connect("extendedBolusStop");
if (!isConnected()) return false;
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
waitMsec(200);
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
return true;
}