move plugins to MainApp, improve dataservice

This commit is contained in:
Milos Kozak 2016-07-18 20:19:55 +02:00
parent fe72300790
commit 3e3ad1d515
20 changed files with 340 additions and 356 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -34,12 +34,12 @@
<activity android:name=".PreferencesActivity" />
<activity android:name=".AgreementActivity" />
<!-- Receiver from NSClient -->
<receiver
android:name=".receivers.NSClientDataReceiver"
android:name=".receivers.DataReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.NEW_TREATMENT" />
<action android:name="info.nightscout.client.CHANGED_TREATMENT" />
<action android:name="info.nightscout.client.REMOVED_TREATMENT" />
@ -50,15 +50,9 @@
<action android:name="info.nightscout.client.NEW_DEVICESTATUS" />
<action android:name="info.nightscout.client.NEW_CAL" />
<action android:name="info.nightscout.client.NEW_STATUS" />
</intent-filter>
</receiver>
<!-- Receiver from xDrip -->
<receiver
android:name=".receivers.xDripReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<!-- Receive new SMS messages -->
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<!-- Receiver from xDrip -->
<action android:name="com.eveningoutpost.dexdrip.BgEstimate" />
</intent-filter>
</receiver>
@ -66,16 +60,6 @@
<!-- Receiver keepalive, scheduled every 30 min -->
<receiver android:name=".receivers.KeepAliveReceiver" />
<!-- Receive new SMS messages -->
<receiver
android:name=".plugins.SmsCommunicator.Receivers.SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<!-- Service processing incomming data -->
<service
android:name=".Services.DataService"

View file

@ -32,6 +32,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment;
import info.nightscout.androidaps.plugins.MM640g.MM640gFragment;
@ -61,10 +62,6 @@ public class MainActivity extends AppCompatActivity {
private static TabPageAdapter pageAdapter;
private static KeepAliveReceiver keepAliveReceiver;
private static ArrayList<PluginBase> pluginsList = null;
private static ConfigBuilderFragment configBuilderFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -83,35 +80,13 @@ public class MainActivity extends AppCompatActivity {
}
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
registerBus();
if (pluginsList == null) {
pluginsList = new ArrayList<PluginBase>();
// Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance());
if (Config.DANAR) pluginsList.add(DanaRFragment.newInstance());
if (Config.MM640G) pluginsList.add(MM640gFragment.newInstance());
pluginsList.add(VirtualPumpFragment.newInstance());
if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.newInstance());
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.newInstance());
if (Config.LOWSUSPEDENABLED) pluginsList.add(LowSuspendFragment.newInstance());
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.newInstance());
pluginsList.add(NSProfileViewerFragment.newInstance());
pluginsList.add(SimpleProfileFragment.newInstance());
pluginsList.add(TreatmentsFragment.newInstance());
pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(SafetyFragment.newInstance());
if (Config.OBJECTIVESENABLED) pluginsList.add(ObjectivesFragment.newInstance());
pluginsList.add(SourceXdripFragment.newInstance());
pluginsList.add(SourceNSClientFragment.newInstance());
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.newInstance());
pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance());
if (keepAliveReceiver == null) {
registerBus();
keepAliveReceiver = new KeepAliveReceiver();
startService(new Intent(this, ExecutionService.class));
keepAliveReceiver.setAlarm(this);
configBuilderFragment.initialize();
MainApp.setConfigBuilder(configBuilderFragment);
}
setUpTabs(false);
}
@ -130,7 +105,7 @@ public class MainActivity extends AppCompatActivity {
private void setUpTabs(boolean switchToLast) {
pageAdapter = new TabPageAdapter(getSupportFragmentManager());
for (PluginBase f : pluginsList) {
for (PluginBase f : MainApp.getPluginsList()) {
pageAdapter.registerNewFragment((Fragment) f);
}
mPager = (ViewPager) findViewById(R.id.pager);
@ -215,54 +190,4 @@ public class MainActivity extends AppCompatActivity {
}
}
public static ArrayList<PluginBase> getPluginsList() {
return pluginsList;
}
public static ArrayList<PluginBase> getSpecificPluginsList(int type) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getType() == type)
newList.add(p);
}
} else {
log.error("pluginsList=null");
}
return newList;
}
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
newList.add(p);
}
} else {
log.error("pluginsList=null");
}
return newList;
}
@Nullable
public static PluginBase getSpecificPlugin(Class pluginClass) {
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() == pluginClass)
return p;
}
} else {
log.error("pluginsList=null");
}
return null;
}
}

View file

@ -2,16 +2,38 @@ package info.nightscout.androidaps;
import android.app.Application;
import android.content.res.Resources;
import android.support.annotation.Nullable;
import com.crashlytics.android.Crashlytics;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment;
import info.nightscout.androidaps.plugins.MM640g.MM640gFragment;
import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
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.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment;
import io.fabric.sdk.android.Fabric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
@ -26,6 +48,8 @@ public class MainApp extends Application {
private static DatabaseHelper sDatabaseHelper = null;
private static ConfigBuilderFragment sConfigBuilder = null;
private static ArrayList<PluginBase> pluginsList = null;
@Override
public void onCreate() {
super.onCreate();
@ -34,6 +58,31 @@ public class MainApp extends Application {
sBus = new Bus(ThreadEnforcer.ANY);
sInstance = this;
sResources = getResources();
if (pluginsList == null) {
pluginsList = new ArrayList<PluginBase>();
// Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance());
if (Config.DANAR) pluginsList.add(DanaRFragment.newInstance());
if (Config.MM640G) pluginsList.add(MM640gFragment.newInstance());
pluginsList.add(VirtualPumpFragment.newInstance());
if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.newInstance());
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.newInstance());
if (Config.LOWSUSPEDENABLED) pluginsList.add(LowSuspendFragment.newInstance());
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.newInstance());
pluginsList.add(NSProfileViewerFragment.newInstance());
pluginsList.add(SimpleProfileFragment.newInstance());
pluginsList.add(TreatmentsFragment.newInstance());
pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(SafetyFragment.newInstance());
if (Config.OBJECTIVESENABLED) pluginsList.add(ObjectivesFragment.newInstance());
pluginsList.add(SourceXdripFragment.newInstance());
pluginsList.add(SourceNSClientFragment.newInstance());
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.newInstance());
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.newInstance());
MainApp.getConfigBuilder().initialize();
}
}
public static Bus bus() {
@ -65,6 +114,57 @@ public class MainApp extends Application {
return sConfigBuilder;
}
public static ArrayList<PluginBase> getPluginsList() {
return pluginsList;
}
public static ArrayList<PluginBase> getSpecificPluginsList(int type) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getType() == type)
newList.add(p);
}
} else {
log.error("pluginsList=null");
}
return newList;
}
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
newList.add(p);
}
} else {
log.error("pluginsList=null");
}
return newList;
}
@Nullable
public static PluginBase getSpecificPlugin(Class pluginClass) {
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() == pluginClass)
return p;
}
} else {
log.error("pluginsList=null");
}
return null;
}
@Override
public void onTerminate() {
super.onTerminate();

View file

@ -89,8 +89,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResource(R.xml.pref_nightscout);
if (Config.DANAR) {
addPreferencesFromResource(R.xml.pref_danar);
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
if (danaRFragment != null && danaRFragment.isEnabled(PluginBase.PROFILE)) {
DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
if (danaRFragment.isEnabled(PluginBase.PROFILE)) {
addPreferencesFromResource(R.xml.pref_danarprofile);
}
}

View file

@ -7,7 +7,6 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Telephony;
import android.support.annotation.Nullable;
import android.telephony.SmsMessage;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
@ -23,9 +22,12 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
@ -34,7 +36,6 @@ import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
@ -43,8 +44,7 @@ import info.nightscout.androidaps.plugins.SmsCommunicator.Events.EventNewSMS;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.receivers.NSClientDataReceiver;
import info.nightscout.androidaps.receivers.xDripReceiver;
import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv;
import info.nightscout.utils.ToastUtils;
@ -57,14 +57,18 @@ public class DataService extends IntentService {
boolean nsClientEnabled = true;
SmsCommunicatorFragment smsCommunicatorFragment = null;
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
private static ScheduledFuture<?> scheduledDisconnection = null;
public DataService() {
super("DataService");
registerBus();
}
@Override
protected void onHandleIntent(Intent intent) {
protected void onHandleIntent(final Intent intent) {
if (Config.logFunctionCalls)
log.debug("onHandleIntent");
log.debug("onHandleIntent " + intent);
if (MainApp.getConfigBuilder() != null) {
if (MainApp.getConfigBuilder().getActiveBgSource().getClass().equals(SourceXdripFragment.class)) {
@ -76,8 +80,8 @@ public class DataService extends IntentService {
nsClientEnabled = true;
}
if (MainActivity.getSpecificPlugin(SmsCommunicatorFragment.class) != null) {
smsCommunicatorFragment = (SmsCommunicatorFragment) MainActivity.getSpecificPlugin(SmsCommunicatorFragment.class);
if (MainApp.getSpecificPlugin(SmsCommunicatorFragment.class) != null) {
smsCommunicatorFragment = (SmsCommunicatorFragment) MainApp.getSpecificPlugin(SmsCommunicatorFragment.class);
}
}
@ -86,7 +90,6 @@ public class DataService extends IntentService {
if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) {
if (xDripEnabled)
handleNewDataFromXDrip(intent);
xDripReceiver.completeWakefulIntent(intent);
} else if (Intents.ACTION_NEW_PROFILE.equals(action) ||
Intents.ACTION_NEW_TREATMENT.equals(action) ||
Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
@ -98,14 +101,16 @@ public class DataService extends IntentService {
Intents.ACTION_NEW_MBG.equals(action)
) {
handleNewDataFromNSClient(intent);
NSClientDataReceiver.completeWakefulIntent(intent);
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
handleNewSMS(intent);
NSClientDataReceiver.completeWakefulIntent(intent);
}
DataReceiver.completeWakefulIntent(intent);
}
if (Config.logFunctionCalls)
log.debug("onHandleIntent exit");
}
/*
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
@ -113,12 +118,13 @@ public class DataService extends IntentService {
if (Config.logFunctionCalls)
log.debug("onStartCommand");
registerBus();
return START_STICKY;
}
*/
@Override
public void onDestroy() {
super.onDestroy();
MainApp.bus().unregister(this);
}
@ -163,6 +169,8 @@ public class DataService extends IntentService {
private void handleNewDataFromNSClient(Intent intent) {
Bundle bundles = intent.getExtras();
if (bundles == null) return;
if (Config.logIncommingData)
log.debug("Got intent: " + intent.getAction());
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
@ -176,7 +184,7 @@ public class DataService extends IntentService {
configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
configBuilderFragment.nsClientVersionName = bundles.getString("nsclientversionname");
log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName);
if (configBuilderFragment.nsClientVersionCode < 117)
if (configBuilderFragment.nsClientVersionCode < 118)
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.unsupportedclientver));
}
} else {
@ -189,7 +197,7 @@ public class DataService extends IntentService {
JSONObject settings = statusJson.getJSONObject("settings");
if (settings.has("thresholds")) {
JSONObject thresholds = settings.getJSONObject("thresholds");
OverviewFragment overviewFragment = (OverviewFragment) MainActivity.getSpecificPlugin(OverviewFragment.class);
OverviewFragment overviewFragment = (OverviewFragment) MainApp.getSpecificPlugin(OverviewFragment.class);
if (overviewFragment != null && thresholds.has("bgTargetTop")) {
overviewFragment.bgTargetHigh = thresholds.getDouble("bgTargetTop");
}
@ -213,7 +221,7 @@ public class DataService extends IntentService {
JSONObject devicestatusJson = jsonArray.getJSONObject(0);
if (devicestatusJson.has("pump")) {
// Objectives 0
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainApp.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) {
objectivesFragment.pumpStatusIsAvailableInNS = true;
objectivesFragment.saveProgress();
@ -232,7 +240,6 @@ public class DataService extends IntentService {
String activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile");
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile);
EventNewBasalProfile event = new EventNewBasalProfile(nsProfile);
if (MainApp.getConfigBuilder() == null) {
log.error("Config builder not ready on receive profile");
return;
@ -247,61 +254,27 @@ public class DataService extends IntentService {
}
if (Config.logIncommingData)
log.debug("Received profile: " + activeProfile + " " + profile);
MainApp.bus().post(event);
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
} catch (JSONException e) {
e.printStackTrace();
}
}
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT)) {
try {
String trstring = bundles.getString("treatment");
JSONObject trJson = new JSONObject(trstring);
if (!trJson.has("insulin") && !trJson.has("carbs")) {
if (Config.logIncommingData)
log.debug("ADD: Uninterested treatment: " + trstring);
return;
if (bundles.containsKey("treatment")) {
String trstring = bundles.getString("treatment");
handleAddedTreatment(trstring);
}
Treatment stored = null;
trJson = new JSONObject(trstring);
String _id = trJson.getString("_id");
if (trJson.has("timeIndex")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = findByTimeIndex(trJson.getLong("timeIndex"));
} else {
stored = findById(_id);
}
if (stored != null) {
if (Config.logIncommingData)
log.debug("ADD: Existing treatment: " + trstring);
if (trJson.has("timeIndex")) {
stored._id = _id;
MainApp.getDbHelper().getDaoTreatments().update(stored);
if (bundles.containsKey("treatments")) {
String trstring = bundles.getString("treatments");
JSONArray jsonArray = new JSONArray(trstring);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject trJson = jsonArray.getJSONObject(i);
String trstr = trJson.toString();
handleAddedTreatment(trstr);
}
MainApp.bus().post(new EventTreatmentChange());
return;
} else {
if (Config.logIncommingData)
log.debug("ADD: New treatment: " + trstring);
Treatment treatment = new Treatment();
treatment._id = _id;
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.setTimeIndex(treatment.getTimeIndex());
try {
MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
if (Config.logIncommingData)
log.debug("ADD: Stored treatment: " + treatment.log());
} catch (SQLException e) {
e.printStackTrace();
}
MainApp.bus().post(new EventTreatmentChange());
}
scheduleTreatmentChange();
} catch (Exception e) {
e.printStackTrace();
}
@ -310,55 +283,20 @@ public class DataService extends IntentService {
if (intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
try {
String trstring = bundles.getString("treatment");
JSONObject trJson = new JSONObject(trstring);
if (!trJson.has("insulin") && !trJson.has("carbs")) {
if (Config.logIncommingData)
log.debug("CHANGE: Uninterested treatment: " + trstring);
return;
if (bundles.containsKey("treatment")) {
String trstring = bundles.getString("treatment");
handleChangedTreatment(trstring);
}
trJson = new JSONObject(trstring);
String _id = trJson.getString("_id");
Treatment stored;
if (trJson.has("timeIndex")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = findByTimeIndex(trJson.getLong("timeIndex"));
} else {
stored = findById(_id);
}
if (stored != null) {
if (Config.logIncommingData)
log.debug("CHANGE: Existing treatment: " + trstring);
stored._id = _id;
stored.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
stored.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
stored.created_at = new Date(trJson.getLong("mills"));
MainApp.getDbHelper().getDaoTreatments().update(stored);
MainApp.bus().post(new EventTreatmentChange());
} else {
if (Config.logIncommingData)
log.debug("CHANGE: New treatment: " + trstring);
Treatment treatment = new Treatment();
treatment._id = _id;
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.setTimeIndex(treatment.getTimeIndex());
try {
MainApp.getDbHelper().getDaoTreatments().create(treatment);
if (Config.logIncommingData)
log.debug("CHANGE: Stored treatment: " + treatment.log());
} catch (SQLException e) {
e.printStackTrace();
if (bundles.containsKey("treatments")) {
String trstring = bundles.getString("treatments");
JSONArray jsonArray = new JSONArray(trstring);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject trJson = jsonArray.getJSONObject(i);
String trstr = trJson.toString();
handleChangedTreatment(trstr);
}
MainApp.bus().post(new EventTreatmentChange());
}
scheduleTreatmentChange();
} catch (Exception e) {
e.printStackTrace();
}
@ -382,8 +320,7 @@ public class DataService extends IntentService {
removeTreatmentFromDb(_id);
}
}
MainApp.bus().post(new EventTreatmentChange());
scheduleTreatmentChange();
} catch (Exception e) {
e.printStackTrace();
}
@ -430,12 +367,110 @@ public class DataService extends IntentService {
MainApp.bus().post(new EventNewBG());
}
// Objectives 0
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainApp.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) {
objectivesFragment.bgIsAvailableInNS = true;
objectivesFragment.saveProgress();
}
}
if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) {
log.error("Not implemented yet"); // TODO implemeng MBGS
}
}
private void handleAddedTreatment(String trstring) throws JSONException, SQLException {
JSONObject trJson = new JSONObject(trstring);
if (!trJson.has("insulin") && !trJson.has("carbs")) {
if (Config.logIncommingData)
log.debug("ADD: Uninterested treatment: " + trstring);
return;
}
Treatment stored = null;
trJson = new JSONObject(trstring);
String _id = trJson.getString("_id");
if (trJson.has("timeIndex")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = findByTimeIndex(trJson.getLong("timeIndex"));
} else {
stored = findById(_id);
}
if (stored != null) {
if (Config.logIncommingData)
log.debug("ADD: Existing treatment: " + trstring);
if (trJson.has("timeIndex")) {
stored._id = _id;
int updated = MainApp.getDbHelper().getDaoTreatments().update(stored);
if (Config.logIncommingData)
log.debug("Records updated: " + updated);
}
return;
} else {
if (Config.logIncommingData)
log.debug("ADD: New treatment: " + trstring);
Treatment treatment = new Treatment();
treatment._id = _id;
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.setTimeIndex(treatment.getTimeIndex());
try {
MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
if (Config.logIncommingData)
log.debug("ADD: Stored treatment: " + treatment.log());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private void handleChangedTreatment(String trstring) throws JSONException, SQLException {
JSONObject trJson = new JSONObject(trstring);
if (!trJson.has("insulin") && !trJson.has("carbs")) {
if (Config.logIncommingData)
log.debug("CHANGE: Uninterested treatment: " + trstring);
return;
}
String _id = trJson.getString("_id");
Treatment stored;
if (trJson.has("timeIndex")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = findByTimeIndex(trJson.getLong("timeIndex"));
} else {
stored = findById(_id);
}
if (stored != null) {
if (Config.logIncommingData)
log.debug("CHANGE: Removing old: " + trstring);
removeTreatmentFromDb(_id);
}
if (Config.logIncommingData)
log.debug("CHANGE: Adding new treatment: " + trstring);
Treatment treatment = new Treatment();
treatment._id = _id;
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.setTimeIndex(treatment.getTimeIndex());
try {
Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
if (Config.logIncommingData)
log.debug("Records updated: " + status.getNumLinesChanged());
if (Config.logIncommingData)
log.debug("CHANGE: Stored treatment: " + treatment.log());
} catch (SQLException e) {
e.printStackTrace();
}
}
@Nullable
@ -489,8 +524,10 @@ public class DataService extends IntentService {
Treatment stored = findById(_id);
if (stored != null) {
log.debug("REMOVE: Existing treatment (removing): " + _id);
MainApp.getDbHelper().getDaoTreatments().delete(stored);
MainApp.bus().post(new EventTreatmentChange());
int removed = MainApp.getDbHelper().getDaoTreatments().delete(stored);
if (Config.logIncommingData)
log.debug("Records removed: " + removed);
scheduleTreatmentChange();
} else {
log.debug("REMOVE: Not stored treatment (ignoring): " + _id);
}
@ -502,4 +539,27 @@ public class DataService extends IntentService {
MainApp.bus().post(new EventNewSMS(bundle));
}
public void scheduleTreatmentChange() {
/*
class DisconnectRunnable implements Runnable {
public void run() {
if (Config.logIncommingData)
log.debug("Firing EventTreatmentChange");
MainApp.bus().post(new EventTreatmentChange());
scheduledDisconnection = null;
}
}
// prepare task for execution in 5 sec
// cancel waiting task to prevent sending multiple disconnections
if (scheduledDisconnection != null)
scheduledDisconnection.cancel(false);
Runnable task = new DisconnectRunnable();
final int sec = 5;
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
log.debug("Scheduling EventTreatmentChange");
*/
MainApp.bus().post(new EventTreatmentChange());
}
}

View file

@ -113,7 +113,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
public void initialize() {
pluginList = MainActivity.getPluginsList();
pluginList = MainApp.getPluginsList();
loadSettings();
}
@ -158,35 +158,35 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
void setViews() {
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(BgSourceInterface.class), PluginBase.BGSOURCE);
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class), PluginBase.BGSOURCE);
bgsourceListView.setAdapter(bgsourceDataAdapter);
setListViewHeightBasedOnChildren(bgsourceListView);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP), PluginBase.PUMP);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.PUMP), PluginBase.PUMP);
pumpListView.setAdapter(pumpDataAdapter);
setListViewHeightBasedOnChildren(pumpListView);
loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.LOOP), PluginBase.LOOP);
loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.LOOP), PluginBase.LOOP);
loopListView.setAdapter(loopDataAdapter);
setListViewHeightBasedOnChildren(loopListView);
if (MainActivity.getSpecificPluginsList(PluginBase.LOOP).size() == 0)
if (MainApp.getSpecificPluginsList(PluginBase.LOOP).size() == 0)
loopLabel.setVisibility(View.GONE);
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TREATMENT), PluginBase.TREATMENT);
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.TREATMENT), PluginBase.TREATMENT);
treatmentsListView.setAdapter(treatmentsDataAdapter);
setListViewHeightBasedOnChildren(treatmentsListView);
tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL), PluginBase.TEMPBASAL);
tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.TEMPBASAL), PluginBase.TEMPBASAL);
tempsListView.setAdapter(tempsDataAdapter);
setListViewHeightBasedOnChildren(tempsListView);
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class), PluginBase.PROFILE);
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsListByInterface(ProfileInterface.class), PluginBase.PROFILE);
profileListView.setAdapter(profileDataAdapter);
setListViewHeightBasedOnChildren(profileListView);
apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.APS), PluginBase.APS);
apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.APS), PluginBase.APS);
apsListView.setAdapter(apsDataAdapter);
setListViewHeightBasedOnChildren(apsListView);
if (MainActivity.getSpecificPluginsList(PluginBase.APS).size() == 0)
if (MainApp.getSpecificPluginsList(PluginBase.APS).size() == 0)
apsLabel.setVisibility(View.GONE);
constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class), PluginBase.CONSTRAINTS);
constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class), PluginBase.CONSTRAINTS);
constraintsListView.setAdapter(constraintsDataAdapter);
setListViewHeightBasedOnChildren(constraintsListView);
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.GENERAL), PluginBase.GENERAL);
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsList(PluginBase.GENERAL), PluginBase.GENERAL);
generalListView.setAdapter(generalDataAdapter);
setListViewHeightBasedOnChildren(generalListView);
@ -650,15 +650,15 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
break;
// Single selection allowed
case PluginBase.PROFILE:
pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class);
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);
break;
case PluginBase.BGSOURCE:
pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(BgSourceInterface.class);
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
break;
case PluginBase.TEMPBASAL:
case PluginBase.TREATMENT:
case PluginBase.PUMP:
pluginsInCategory = MainActivity.getSpecificPluginsList(category);
pluginsInCategory = MainApp.getSpecificPluginsList(category);
break;
}
if (pluginsInCategory != null) {
@ -683,7 +683,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
ArrayList<PluginBase> pluginsInCategory;
// PluginBase.PROFILE
pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class);
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);
activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PROFILE);
if (Config.logConfigBuilder)
log.debug("Selected profile interface: " + ((PluginBase) activeProfile).getName());
@ -694,7 +694,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
// PluginBase.BGSOURCE
pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(BgSourceInterface.class);
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
activeBgSource = (BgSourceInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.BGSOURCE);
if (Config.logConfigBuilder)
log.debug("Selected bgSource interface: " + ((PluginBase) activeBgSource).getName());
@ -705,7 +705,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
// PluginBase.PUMP
pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.PUMP);
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP);
activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP);
if (Config.logConfigBuilder)
log.debug("Selected pump interface: " + ((PluginBase) activePump).getName());
@ -716,7 +716,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
// PluginBase.LOOP
pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.LOOP);
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.LOOP);
activeLoop = (LoopFragment) getTheOneEnabledInArray(pluginsInCategory, PluginBase.LOOP);
if (activeLoop != null) {
if (Config.logConfigBuilder)
@ -729,7 +729,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
// PluginBase.TEMPBASAL
pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL);
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TEMPBASAL);
activeTempBasals = (TempBasalsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TEMPBASAL);
if (Config.logConfigBuilder)
log.debug("Selected tempbasal interface: " + ((PluginBase) activeTempBasals).getName());
@ -740,7 +740,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
// PluginBase.TREATMENT
pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.TREATMENT);
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TREATMENT);
activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TREATMENT);
if (Config.logConfigBuilder)
log.debug("Selected treatment interface: " + ((PluginBase) activeTreatments).getName());
@ -839,7 +839,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public boolean isLoopEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -852,7 +852,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public boolean isClosedModeEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -865,7 +865,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public boolean isAutosensModeEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -878,7 +878,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public boolean isAMAModeEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -890,7 +890,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Double applyBasalConstraints(Double absoluteRate) {
Double rateAfterConstrain = absoluteRate;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -902,7 +902,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Integer applyBasalConstraints(Integer percentRate) {
Integer rateAfterConstrain = percentRate;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -914,7 +914,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Double applyBolusConstraints(Double insulin) {
Double insulinAfterConstrain = insulin;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -926,7 +926,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Integer applyCarbsConstraints(Integer carbs) {
Integer carbsAfterConstrain = carbs;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
@ -938,7 +938,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Double applyMaxIOBConstraints(Double maxIob) {
Double maxIobAfterConstrain = maxIob;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;

View file

@ -195,6 +195,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) {
log.debug("Service is disconnected");
mBounded = false;
mExecutionService = null;
}
@ -321,6 +322,10 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
@Override
public void setNewBasalProfile(NSProfile profile) {
if (mExecutionService == null) {
log.error("setNewBasalProfile mExecutionService is null");
return;
}
if (!mExecutionService.updateBasalsInPump(profile))
ToastUtils.showToastInUiThread(getContext(), MainApp.sResources.getString(R.string.failedupdatebasalprofile));
}
@ -705,7 +710,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
}
public static void doConnect(String from) {
mExecutionService.connect(from);
if (mExecutionService != null) mExecutionService.connect(from);
}
@Override

View file

@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.client.data.NSProfile;
@ -48,7 +49,7 @@ public class ProfileViewDialog extends DialogFragment {
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
profile = ((DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class)).getProfile();
profile = ((DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class)).getProfile();
}
@Override

View file

@ -104,11 +104,9 @@ public class ExecutionService extends Service {
public ExecutionService() {
registerBus();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
if (danaRFragment != null)
danaRPump = danaRFragment.getDanaRPump();
else
log.error("danaRFragment is null");
DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
danaRPump = danaRFragment.getDanaRPump();
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaConnection");
}

View file

@ -63,7 +63,7 @@ public class MsgStatusBolusExtended extends MessageBase {
}
public static void updateExtendedBolusInDB() {
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
DanaRPump danaRPump = danaRFragment.getDanaRPump();
Date now = new Date();

View file

@ -54,7 +54,7 @@ public class MsgStatusTempBasal extends MessageBase {
}
public static void updateTempBasalInDB() {
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
DanaRPump danaRPump = danaRFragment.getDanaRPump();
Date now = new Date();

View file

@ -242,7 +242,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
return;
APSInterface usedAPS = null;
ArrayList<PluginBase> apsPlugins = MainActivity.getSpecificPluginsList(PluginBase.APS);
ArrayList<PluginBase> apsPlugins = MainApp.getSpecificPluginsList(PluginBase.APS);
for (PluginBase p : apsPlugins) {
APSInterface aps = (APSInterface) p;
if (!p.isEnabled(PluginBase.APS)) continue;

View file

@ -62,7 +62,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
@Override
public boolean isVisibleInTabs(int type) {
LoopFragment loopFragment = (LoopFragment) MainActivity.getSpecificPlugin(LoopFragment.class);
LoopFragment loopFragment = (LoopFragment) MainApp.getSpecificPlugin(LoopFragment.class);
return fragmentVisible && loopFragment != null && loopFragment.isVisibleInTabs(type);
}

View file

@ -263,7 +263,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
MainApp.getConfigBuilder().uploadDeviceStatus();
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainApp.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) {
objectivesFragment.manualEnacts++;
objectivesFragment.saveProgress();

View file

@ -1,29 +0,0 @@
package info.nightscout.androidaps.plugins.SmsCommunicator.Receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.telephony.SmsMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment;
public class SmsReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(SmsReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {
if (Config.logFunctionCalls)
log.debug("onReceive " + intent);
startWakefulService(context, new Intent(context, DataService.class)
.setAction(intent.getAction())
.putExtras(intent));
}
}

View file

@ -194,7 +194,7 @@ public class SmsCommunicatorFragment extends Fragment implements PluginBase {
receivedSms.processed = true;
break;
case "DANAR":
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
if (danaRFragment != null) reply = danaRFragment.shortStatus();
receivedSms.processed = true;
break;
@ -225,7 +225,7 @@ public class SmsCommunicatorFragment extends Fragment implements PluginBase {
bolusWaitingForConfirmation.processed = true;
PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump();
if (pumpInterface != null) {
danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0);
if (result.success) {
reply = String.format(MainApp.sResources.getString(R.string.bolusdelivered), bolusWaitingForConfirmation.bolusRequested);

View file

@ -7,14 +7,11 @@ import android.support.v4.content.WakefulBroadcastReceiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
public class xDripReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(xDripReceiver.class);
public class DataReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(DataReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {

View file

@ -29,26 +29,6 @@ import info.nightscout.utils.ToastUtils;
public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);
private boolean mBounded;
private static ExecutionService mExecutionService;
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "ExecutionService is disconnected"); // TODO: remove
mBounded = false;
mExecutionService = null;
}
public void onServiceConnected(ComponentName name, IBinder service) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "ExecutionService is connected"); // TODO: remove
log.debug("Service is connected");
mBounded = true;
ExecutionService.LocalBinder mLocalBinder = (ExecutionService.LocalBinder) service;
mExecutionService = mLocalBinder.getServiceInstance();
}
};
@Override
public void onReceive(Context context, Intent rIntent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
@ -56,12 +36,12 @@ public class KeepAliveReceiver extends BroadcastReceiver {
wl.acquire();
log.debug("KeepAlive received");
DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
if (Config.DANAR && danaRFragment != null && danaRFragment.isEnabled(PluginBase.PUMP)) {
final DanaRFragment danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
if (Config.DANAR && danaRFragment.isEnabled(PluginBase.PUMP)) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
mExecutionService.connect("KeepAlive");
danaRFragment.doConnect("KeepAlive");
}
});
t.start();
@ -80,10 +60,6 @@ public class KeepAliveReceiver extends BroadcastReceiver {
}
am.cancel(pi);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.keepAliveMsecs, pi);
// DanaR bind
Intent intent = new Intent(context, ExecutionService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
public void cancelAlarm(Context context) {
@ -91,11 +67,5 @@ public class KeepAliveReceiver extends BroadcastReceiver {
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
// DanaR bind
if (mBounded) {
context.unbindService(mConnection);
mBounded = false;
}
}
}

View file

@ -1,27 +0,0 @@
package info.nightscout.androidaps.receivers;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
public class NSClientDataReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(NSClientDataReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {
if (Config.logFunctionCalls)
log.debug("onReceive " + intent);
startWakefulService(context, new Intent(context, DataService.class)
.setAction(intent.getAction())
.putExtras(intent));
}
}