AndroidAPS/app/src/main/java/info/nightscout/androidaps/MainApp.java

73 lines
1.9 KiB
Java
Raw Normal View History

2016-06-05 01:40:35 +02:00
package info.nightscout.androidaps;
import android.app.Application;
import android.content.res.Resources;
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-06-24 17:48:11 +02:00
import io.fabric.sdk.android.Fabric;
2016-06-05 01:40:35 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
2016-06-05 01:40:35 +02:00
public class MainApp extends Application {
private static Logger log = LoggerFactory.getLogger(MainApp.class);
private static Bus sBus;
private static MainApp sInstance;
public static Resources resources;
2016-06-05 01:40:35 +02:00
private static DatabaseHelper databaseHelper = null;
private static ConfigBuilderFragment configBuilder = 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-06-05 01:40:35 +02:00
sBus = new Bus(ThreadEnforcer.ANY);
sInstance = this;
resources = getResources();
2016-06-05 01:40:35 +02:00
}
public static Bus bus() {
return sBus;
}
public static MainApp instance() {
return sInstance;
}
public static DatabaseHelper getDbHelper() {
if (databaseHelper == null) {
databaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
}
return databaseHelper;
}
public static void closeDbHelper() {
if (databaseHelper != null) {
databaseHelper.close();
databaseHelper = null;
}
}
public static void setConfigBuilder(ConfigBuilderFragment cb) {
configBuilder = cb;
}
public static ConfigBuilderFragment getConfigBuilder() {
return configBuilder;
}
2016-06-05 01:40:35 +02:00
@Override
public void onTerminate() {
super.onTerminate();
databaseHelper.close();
}
}