2016-06-05 01:40:35 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
|
|
|
import com.squareup.otto.Bus;
|
|
|
|
import com.squareup.otto.ThreadEnforcer;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
2016-06-21 23:24:54 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
private static DatabaseHelper databaseHelper = null;
|
2016-06-21 23:24:54 +02:00
|
|
|
private static ConfigBuilderFragment configBuilder = null;
|
2016-06-05 01:40:35 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
|
|
|
|
sBus = new Bus(ThreadEnforcer.ANY);
|
|
|
|
sInstance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 23:24:54 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|