2016-06-05 01:40:35 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
|
|
|
import android.app.Application;
|
2016-06-24 17:16:17 +02:00
|
|
|
import android.content.res.Resources;
|
2016-07-18 20:19:55 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2016-06-24 17:48:11 +02:00
|
|
|
import com.crashlytics.android.Crashlytics;
|
2016-06-05 01:40:35 +02:00
|
|
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
|
|
|
import com.squareup.otto.Bus;
|
|
|
|
import com.squareup.otto.ThreadEnforcer;
|
|
|
|
|
2016-08-05 23:54:03 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
2016-07-18 20:19:55 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2016-11-05 15:46:11 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
2016-07-18 20:19:55 +02:00
|
|
|
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
2016-11-12 17:32:32 +01:00
|
|
|
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment;
|
2016-08-05 23:54:03 +02:00
|
|
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
|
|
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
2016-07-18 20:19:55 +02:00
|
|
|
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
|
|
|
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
|
|
|
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;
|
2016-06-24 17:48:11 +02:00
|
|
|
import io.fabric.sdk.android.Fabric;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
|
|
|
|
2016-08-05 23:54:03 +02:00
|
|
|
public class MainApp extends Application {
|
2016-06-05 01:40:35 +02:00
|
|
|
private static Logger log = LoggerFactory.getLogger(MainApp.class);
|
|
|
|
|
|
|
|
private static Bus sBus;
|
|
|
|
private static MainApp sInstance;
|
2016-07-07 10:34:20 +02:00
|
|
|
public static Resources sResources;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2016-07-07 10:34:20 +02:00
|
|
|
private static DatabaseHelper sDatabaseHelper = null;
|
2016-08-05 23:54:03 +02:00
|
|
|
private static ConfigBuilderPlugin sConfigBuilder = null;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
private static ArrayList<PluginBase> pluginsList = null;
|
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2016-06-24 17:48:11 +02:00
|
|
|
Fabric.with(this, new Crashlytics());
|
2016-11-08 19:10:25 +01:00
|
|
|
Crashlytics.setString("BUILDVERSION", BuildConfig.BUILDVERSION);
|
|
|
|
log.info("Version: " + BuildConfig.VERSION_NAME);
|
|
|
|
log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
|
2016-06-05 01:40:35 +02:00
|
|
|
|
|
|
|
sBus = new Bus(ThreadEnforcer.ANY);
|
|
|
|
sInstance = this;
|
2016-07-07 10:34:20 +02:00
|
|
|
sResources = getResources();
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
if (pluginsList == null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
pluginsList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
// Register all tabs in app here
|
2016-08-05 23:54:03 +02:00
|
|
|
pluginsList.add(OverviewFragment.getPlugin());
|
2016-11-05 15:46:11 +01:00
|
|
|
pluginsList.add(ActionsFragment.getPlugin());
|
2016-08-05 23:54:03 +02:00
|
|
|
if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin());
|
|
|
|
if (Config.MM640G) pluginsList.add(MM640gFragment.getPlugin());
|
|
|
|
if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.getPlugin());
|
2016-09-08 23:37:44 +02:00
|
|
|
pluginsList.add(VirtualPumpFragment.getPlugin());
|
2016-08-05 23:54:03 +02:00
|
|
|
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin());
|
|
|
|
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin());
|
|
|
|
pluginsList.add(NSProfileViewerFragment.getPlugin());
|
|
|
|
pluginsList.add(SimpleProfileFragment.getPlugin());
|
2016-11-12 17:32:32 +01:00
|
|
|
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
2016-08-05 23:54:03 +02:00
|
|
|
pluginsList.add(TreatmentsFragment.getPlugin());
|
|
|
|
pluginsList.add(TempBasalsFragment.getPlugin());
|
|
|
|
pluginsList.add(SafetyFragment.getPlugin());
|
|
|
|
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
|
|
|
|
pluginsList.add(SourceXdripFragment.getPlugin());
|
|
|
|
pluginsList.add(SourceNSClientFragment.getPlugin());
|
|
|
|
if (Config.SMSCOMMUNICATORENABLED)
|
|
|
|
pluginsList.add(SmsCommunicatorFragment.getPlugin());
|
|
|
|
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
MainApp.getConfigBuilder().initialize();
|
|
|
|
}
|
2016-11-10 16:42:59 +01:00
|
|
|
MainApp.getConfigBuilder().uploadAppStart();
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Bus bus() {
|
|
|
|
return sBus;
|
|
|
|
}
|
2016-08-05 23:54:03 +02:00
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
public static MainApp instance() {
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static DatabaseHelper getDbHelper() {
|
2016-07-07 10:34:20 +02:00
|
|
|
if (sDatabaseHelper == null) {
|
|
|
|
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
2016-07-07 10:34:20 +02:00
|
|
|
return sDatabaseHelper;
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void closeDbHelper() {
|
2016-07-07 10:34:20 +02:00
|
|
|
if (sDatabaseHelper != null) {
|
|
|
|
sDatabaseHelper.close();
|
|
|
|
sDatabaseHelper = null;
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 23:54:03 +02:00
|
|
|
public static ConfigBuilderPlugin getConfigBuilder() {
|
2016-07-07 10:34:20 +02:00
|
|
|
return sConfigBuilder;
|
2016-06-21 23:24:54 +02:00
|
|
|
}
|
|
|
|
|
2016-07-18 20:19:55 +02:00
|
|
|
public static ArrayList<PluginBase> getPluginsList() {
|
|
|
|
return pluginsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsList(int type) {
|
2016-08-05 23:54:03 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
2016-07-18 20:19:55 +02:00
|
|
|
if (p.getType() == type)
|
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
2016-08-05 23:54:03 +02:00
|
|
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
2016-07-18 20:19:55 +02:00
|
|
|
|
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
|
|
|
if (p.getClass() != ConfigBuilderPlugin.class && interfaceClass.isAssignableFrom(p.getClass()))
|
2016-07-18 20:19:55 +02:00
|
|
|
newList.add(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public static PluginBase getSpecificPlugin(Class pluginClass) {
|
|
|
|
if (pluginsList != null) {
|
2016-08-05 23:54:03 +02:00
|
|
|
for (PluginBase p : pluginsList) {
|
2016-07-18 20:19:55 +02:00
|
|
|
if (p.getClass() == pluginClass)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.error("pluginsList=null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:40:35 +02:00
|
|
|
@Override
|
|
|
|
public void onTerminate() {
|
|
|
|
super.onTerminate();
|
2016-07-07 10:34:20 +02:00
|
|
|
sDatabaseHelper.close();
|
2016-06-05 01:40:35 +02:00
|
|
|
}
|
|
|
|
}
|