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;
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;
private static ConfigBuilderFragment sConfigBuilder = 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;
2016-07-07 10:34:20 +02:00
sResources = 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() {
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
}
}
public static void setConfigBuilder(ConfigBuilderFragment cb) {
2016-07-07 10:34:20 +02:00
sConfigBuilder = cb;
}
public static ConfigBuilderFragment getConfigBuilder() {
2016-07-07 10:34:20 +02:00
return sConfigBuilder;
}
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
}
}