package info.nightscout.androidaps; import android.app.Application; import android.content.res.Resources; import com.crashlytics.android.Crashlytics; import com.j256.ormlite.android.apptools.OpenHelperManager; import com.squareup.otto.Bus; import com.squareup.otto.ThreadEnforcer; import io.fabric.sdk.android.Fabric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; public class MainApp extends Application { private static Logger log = LoggerFactory.getLogger(MainApp.class); private static Bus sBus; private static MainApp sInstance; public static Resources sResources; private static DatabaseHelper sDatabaseHelper = null; private static ConfigBuilderFragment sConfigBuilder = null; @Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); sBus = new Bus(ThreadEnforcer.ANY); sInstance = this; sResources = getResources(); } public static Bus bus() { return sBus; } public static MainApp instance() { return sInstance; } public static DatabaseHelper getDbHelper() { if (sDatabaseHelper == null) { sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class); } return sDatabaseHelper; } public static void closeDbHelper() { if (sDatabaseHelper != null) { sDatabaseHelper.close(); sDatabaseHelper = null; } } public static void setConfigBuilder(ConfigBuilderFragment cb) { sConfigBuilder = cb; } public static ConfigBuilderFragment getConfigBuilder() { return sConfigBuilder; } @Override public void onTerminate() { super.onTerminate(); sDatabaseHelper.close(); } }