make all getDao private
This commit is contained in:
parent
6004a17594
commit
85e6375026
|
@ -28,7 +28,6 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
|
@ -50,7 +49,6 @@ import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
|||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||
|
@ -192,12 +190,7 @@ public class DataService extends IntentService {
|
|||
if (Config.logIncommingBG)
|
||||
log.debug("XDRIPREC BG " + bgReading.toString());
|
||||
|
||||
try {
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading);
|
||||
}
|
||||
|
||||
private void handleNewDataFromGlimp(Intent intent) {
|
||||
|
@ -215,12 +208,7 @@ public class DataService extends IntentService {
|
|||
log.debug(bundle.toString());
|
||||
log.debug("GLIMP BG " + bgReading.toString());
|
||||
|
||||
try {
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading);
|
||||
}
|
||||
|
||||
private void handleNewDataFromMM640g(Intent intent) {
|
||||
|
@ -257,11 +245,7 @@ public class DataService extends IntentService {
|
|||
if (Config.logIncommingBG)
|
||||
log.debug("MM640g BG " + bgReading.toString());
|
||||
|
||||
try {
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading);
|
||||
break;
|
||||
default:
|
||||
log.debug("Unknown entries type: " + type);
|
||||
|
@ -272,7 +256,6 @@ public class DataService extends IntentService {
|
|||
}
|
||||
}
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
|
||||
private void handleNewDataFromNSClient(Intent intent) {
|
||||
|
@ -423,7 +406,7 @@ public class DataService extends IntentService {
|
|||
String trstring = bundles.getString("treatment");
|
||||
JSONObject trJson = new JSONObject(trstring);
|
||||
String _id = trJson.getString("_id");
|
||||
MainApp.getDbHelper().delete(_id);
|
||||
MainApp.getDbHelper().deleteTreatmentById(_id);
|
||||
handleRemoveTempTargetRecord(trJson);
|
||||
}
|
||||
|
||||
|
@ -433,7 +416,7 @@ public class DataService extends IntentService {
|
|||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject trJson = jsonArray.getJSONObject(i);
|
||||
String _id = trJson.getString("_id");
|
||||
MainApp.getDbHelper().delete(_id);
|
||||
MainApp.getDbHelper().deleteTreatmentById(_id);
|
||||
handleRemoveTempTargetRecord(trJson);
|
||||
}
|
||||
}
|
||||
|
@ -454,7 +437,7 @@ public class DataService extends IntentService {
|
|||
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||
return;
|
||||
}
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("ADD: Stored new BG: " + bgReading.toString());
|
||||
}
|
||||
|
@ -470,7 +453,7 @@ public class DataService extends IntentService {
|
|||
if (Config.logIncommingData)
|
||||
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||
} else {
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("ADD: Stored new BG: " + bgReading.toString());
|
||||
}
|
||||
|
@ -479,7 +462,6 @@ public class DataService extends IntentService {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) {
|
||||
|
@ -571,7 +553,7 @@ public class DataService extends IntentService {
|
|||
if (stored != null) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("CHANGE: Removing old: " + trstring);
|
||||
MainApp.getDbHelper().delete(_id);
|
||||
MainApp.getDbHelper().deleteTreatmentById(_id);
|
||||
}
|
||||
|
||||
if (Config.logIncommingData)
|
||||
|
@ -605,27 +587,9 @@ public class DataService extends IntentService {
|
|||
log.debug("CHANGE: Stored treatment: " + treatment.log());
|
||||
}
|
||||
|
||||
public void handleDanaRHistoryRecords(JSONObject trJson) throws JSONException, SQLException {
|
||||
public void handleDanaRHistoryRecords(JSONObject trJson) {
|
||||
if (trJson.has(DanaRNSHistorySync.DANARSIGNATURE)) {
|
||||
Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = daoHistoryRecords.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("bytes", trJson.get(DanaRNSHistorySync.DANARSIGNATURE));
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
List<DanaRHistoryRecord> list = daoHistoryRecords.query(preparedQuery);
|
||||
if (list.size() == 0) {
|
||||
// Record does not exists. Ignore
|
||||
} else if (list.size() == 1) {
|
||||
DanaRHistoryRecord record = list.get(0);
|
||||
if (record._id == null || !record._id.equals(trJson.getString("_id"))) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating _id in DanaR history database: " + trJson.getString("_id"));
|
||||
record._id = trJson.getString("_id");
|
||||
daoHistoryRecords.update(record);
|
||||
} else {
|
||||
// already set
|
||||
}
|
||||
}
|
||||
MainApp.getDbHelper().updateDanaRHistoryRecordId(trJson);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -648,62 +612,16 @@ public class DataService extends IntentService {
|
|||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temporary Target")) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Processing TempTarget record: " + trJson.toString());
|
||||
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||
List<TempTarget> list = daoTempTargets.query(preparedQuery);
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null) return; // no profile data, better ignore than do something wrong
|
||||
String units = profile.getUnits();
|
||||
if (list.size() == 0) {
|
||||
// Record does not exists. add
|
||||
TempTarget newRecord = new TempTarget();
|
||||
newRecord.date = trJson.getLong("mills");
|
||||
newRecord.durationInMinutes = trJson.getInt("duration");
|
||||
newRecord.low = NSProfile.toMgdl(trJson.getDouble("targetBottom"), units);
|
||||
newRecord.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
|
||||
newRecord.reason = trJson.getString("reason");
|
||||
newRecord._id = trJson.getString("_id");
|
||||
daoTempTargets.createIfNotExists(newRecord);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Adding TempTarget record to database: " + newRecord.log());
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} else if (list.size() == 1) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating TempTarget record in database: " + trJson.getString("_id"));
|
||||
TempTarget record = list.get(0);
|
||||
record.date = trJson.getLong("mills");
|
||||
record.durationInMinutes = trJson.getInt("duration");
|
||||
record.low = NSProfile.toMgdl(trJson.getDouble("targetBottom"), units);
|
||||
record.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
|
||||
record.reason = trJson.getString("reason");
|
||||
record._id = trJson.getString("_id");
|
||||
daoTempTargets.update(record);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
}
|
||||
MainApp.getDbHelper().createFromJsonIfNotExists(trJson);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRemoveTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||
public void handleRemoveTempTargetRecord(JSONObject trJson) {
|
||||
if (trJson.has("_id")) {
|
||||
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", trJson.getString("_id"));
|
||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||
List<TempTarget> list = daoTempTargets.query(preparedQuery);
|
||||
|
||||
if (list.size() == 1) {
|
||||
TempTarget record = list.get(0);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Removing TempTarget record from database: " + record.log());
|
||||
daoTempTargets.delete(record);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} else {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("TempTarget not found database: " + trJson.toString());
|
||||
try {
|
||||
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,6 @@ public class GlucoseStatus {
|
|||
|
||||
@Nullable
|
||||
public static GlucoseStatus getGlucoseStatusData() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainApp.instance());
|
||||
|
||||
// load 45min
|
||||
long fromtime = (long) (new Date().getTime() - 60 * 1000L * 45);
|
||||
List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
|
||||
|
@ -143,48 +141,6 @@ public class GlucoseStatus {
|
|||
return status.round();
|
||||
}
|
||||
|
||||
/*
|
||||
* Return last BgReading from database or null if db is empty
|
||||
*/
|
||||
@Nullable
|
||||
public static BgReading lastBg() {
|
||||
List<BgReading> bgList = null;
|
||||
|
||||
try {
|
||||
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
||||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
queryBuilder.limit(1L);
|
||||
queryBuilder.where().gt("value", 38);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgList = daoBgReadings.query(preparedQuery);
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
if (bgList != null && bgList.size() > 0)
|
||||
return bgList.get(0);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return bg reading if not old ( <9 min )
|
||||
* or null if older
|
||||
*/
|
||||
@Nullable
|
||||
public static BgReading actualBg() {
|
||||
BgReading lastBg = lastBg();
|
||||
|
||||
if (lastBg == null)
|
||||
return null;
|
||||
|
||||
if (lastBg.date > new Date().getTime() - 9 * 60 * 1000)
|
||||
return lastBg;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double average(ArrayList<Double> array) {
|
||||
double sum = 0d;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
|
@ -13,6 +14,8 @@ import com.j256.ormlite.stmt.Where;
|
|||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -28,8 +31,12 @@ import java.util.concurrent.TimeUnit;
|
|||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
|
||||
|
@ -56,7 +63,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
onCreate(getWritableDatabase(), getConnectionSource());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||
try {
|
||||
|
@ -67,6 +73,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||
} catch (SQLException e) {
|
||||
log.error("Can't create database", e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -83,6 +91,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
TableUtils.dropTable(connectionSource, BgReading.class, true);
|
||||
TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
|
||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
} catch (SQLException e) {
|
||||
log.error("Can't drop databases", e);
|
||||
|
@ -119,8 +129,22 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
|
||||
getWritableDatabase().delete(DATABASE_DANARHISTORY, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
|
||||
|
||||
log.debug("Before TemporaryBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPORARYBASALS));
|
||||
getWritableDatabase().delete(DATABASE_TEMPORARYBASALS, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After TemporaryBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPORARYBASALS));
|
||||
|
||||
log.debug("Before ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
||||
getWritableDatabase().delete(DATABASE_EXTENDEDBOLUSES, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
||||
}
|
||||
|
||||
public long size(String database) {
|
||||
return DatabaseUtils.queryNumEntries(getReadableDatabase(), database);
|
||||
}
|
||||
|
||||
// --------------------- DB resets ---------------------
|
||||
|
||||
public void resetDatabases() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, TempExBasal.class, true);
|
||||
|
@ -128,12 +152,18 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
TableUtils.dropTable(connectionSource, Treatment.class, true);
|
||||
TableUtils.dropTable(connectionSource, BgReading.class, true);
|
||||
TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
|
||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||
//DbRequests can be cleared from NSClient fragment
|
||||
TableUtils.createTableIfNotExists(connectionSource, TempExBasal.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||
latestTreatmentChange = 0L;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -159,11 +189,31 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public Dao<TempExBasal, Long> getDaoTempBasals() throws SQLException {
|
||||
public void resetTemporaryBasals() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void resetExtededBoluses() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------ getDao -------------------------------------------
|
||||
|
||||
private Dao<TempExBasal, Long> getDaoTempBasals() throws SQLException {
|
||||
return getDao(TempExBasal.class);
|
||||
}
|
||||
|
||||
public Dao<TempTarget, Long> getDaoTempTargets() throws SQLException {
|
||||
private Dao<TempTarget, Long> getDaoTempTargets() throws SQLException {
|
||||
return getDao(TempTarget.class);
|
||||
}
|
||||
|
||||
|
@ -171,22 +221,80 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return getDao(Treatment.class);
|
||||
}
|
||||
|
||||
public Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
|
||||
private Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
|
||||
return getDao(BgReading.class);
|
||||
}
|
||||
|
||||
public Dao<DanaRHistoryRecord, String> getDaoDanaRHistory() throws SQLException {
|
||||
private Dao<DanaRHistoryRecord, String> getDaoDanaRHistory() throws SQLException {
|
||||
return getDao(DanaRHistoryRecord.class);
|
||||
}
|
||||
|
||||
public Dao<DbRequest, String> getDaoDbRequest() throws SQLException {
|
||||
private Dao<DbRequest, String> getDaoDbRequest() throws SQLException {
|
||||
return getDao(DbRequest.class);
|
||||
}
|
||||
|
||||
public long size(String database) {
|
||||
return DatabaseUtils.queryNumEntries(getReadableDatabase(), database);
|
||||
private Dao<TemporaryBasal, String> getDaoTemporaryBasal() throws SQLException {
|
||||
return getDao(TemporaryBasal.class);
|
||||
}
|
||||
|
||||
private Dao<ExtendedBolus, String> getDaoExtendedBolus() throws SQLException {
|
||||
return getDao(ExtendedBolus.class);
|
||||
}
|
||||
|
||||
// ------------------- BgReading handling -----------------------
|
||||
|
||||
public void createIfNotExists(BgReading bgReading) {
|
||||
try {
|
||||
getDaoBgReadings().createIfNotExists(bgReading);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
|
||||
/*
|
||||
* Return last BgReading from database or null if db is empty
|
||||
*/
|
||||
@Nullable
|
||||
public static BgReading lastBg() {
|
||||
List<BgReading> bgList = null;
|
||||
|
||||
try {
|
||||
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
||||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
queryBuilder.limit(1L);
|
||||
queryBuilder.where().gt("value", 38);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgList = daoBgReadings.query(preparedQuery);
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
if (bgList != null && bgList.size() > 0)
|
||||
return bgList.get(0);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return bg reading if not old ( <9 min )
|
||||
* or null if older
|
||||
*/
|
||||
@Nullable
|
||||
public static BgReading actualBg() {
|
||||
BgReading lastBg = lastBg();
|
||||
|
||||
if (lastBg == null)
|
||||
return null;
|
||||
|
||||
if (lastBg.date > new Date().getTime() - 9 * 60 * 1000)
|
||||
return lastBg;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<BgReading> getBgreadingsDataFromTime(long mills, boolean ascending) {
|
||||
try {
|
||||
Dao<BgReading, Long> daoBgreadings = getDaoBgReadings();
|
||||
|
@ -204,7 +312,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return new ArrayList<BgReading>();
|
||||
}
|
||||
|
||||
// DbRequests handling
|
||||
// ------------- DbRequests handling -------------------
|
||||
|
||||
public void create(DbRequest dbr) {
|
||||
try {
|
||||
|
@ -260,7 +368,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
// TREATMENT HANDLING
|
||||
public CloseableIterator getDbRequestInterator() {
|
||||
try {
|
||||
return getDaoDbRequest().closeableIterator();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------- TREATMENT HANDLING -------------------
|
||||
|
||||
public boolean affectingIobCob(Treatment t) {
|
||||
Treatment existing = findTreatmentByTimeIndex(t.date);
|
||||
|
@ -319,7 +436,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
scheduleTreatmentChange();
|
||||
}
|
||||
|
||||
public int delete(String _id) {
|
||||
public int deleteTreatmentById(String _id) {
|
||||
Treatment stored = findTreatmentById(_id);
|
||||
int removed = 0;
|
||||
if (stored != null) {
|
||||
|
@ -423,6 +540,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return new ArrayList<Treatment>();
|
||||
}
|
||||
|
||||
// ------------ TempExBasal handling ---------------
|
||||
|
||||
public int update(TempExBasal tempBasal) {
|
||||
int updated = 0;
|
||||
try {
|
||||
|
@ -455,6 +574,25 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
scheduleTreatmentChange();
|
||||
}
|
||||
|
||||
public List<TempExBasal> getTempbasalsDataFromTime(long mills, boolean ascending, boolean isExtended) {
|
||||
try {
|
||||
Dao<TempExBasal, Long> daoTempbasals = getDaoTempBasals();
|
||||
List<TempExBasal> tempbasals;
|
||||
QueryBuilder<TempExBasal, Long> queryBuilder = daoTempbasals.queryBuilder();
|
||||
queryBuilder.orderBy("timeIndex", ascending);
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("timeIndex", mills).and().eq("isExtended", isExtended);
|
||||
PreparedQuery<TempExBasal> preparedQuery = queryBuilder.prepare();
|
||||
tempbasals = daoTempbasals.query(preparedQuery);
|
||||
return tempbasals;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<TempExBasal>();
|
||||
}
|
||||
|
||||
// ---------------- TempTargets handling ---------------
|
||||
|
||||
public List<TempTarget> getTemptargetsDataFromTime(long mills, boolean ascending) {
|
||||
try {
|
||||
Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets();
|
||||
|
@ -472,22 +610,141 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return new ArrayList<TempTarget>();
|
||||
}
|
||||
|
||||
|
||||
public List<TempExBasal> getTempbasalsDataFromTime(long mills, boolean ascending, boolean isExtended) {
|
||||
public void createIfNotExists(TempTarget tempTarget) {
|
||||
try {
|
||||
Dao<TempExBasal, Long> daoTempbasals = getDaoTempBasals();
|
||||
List<TempExBasal> tempbasals;
|
||||
QueryBuilder<TempExBasal, Long> queryBuilder = daoTempbasals.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("date", mills).and().eq("isExtended", isExtended);
|
||||
PreparedQuery<TempExBasal> preparedQuery = queryBuilder.prepare();
|
||||
tempbasals = daoTempbasals.query(preparedQuery);
|
||||
return tempbasals;
|
||||
getDaoTempTargets().createIfNotExists(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<TempExBasal>();
|
||||
}
|
||||
|
||||
public void delete(TempTarget tempTarget) {
|
||||
try {
|
||||
getDaoTempTargets().delete(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void createFromJsonIfNotExists(JSONObject trJson) {
|
||||
try {
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = null;
|
||||
queryBuilder = getDaoTempTargets().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||
List<TempTarget> list = getDaoTempTargets().query(preparedQuery);
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null) return; // no profile data, better ignore than do something wrong
|
||||
String units = profile.getUnits();
|
||||
TempTarget tempTarget;
|
||||
if (list.size() == 0) {
|
||||
tempTarget = new TempTarget();
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Adding TempTarget record to database: " + trJson.toString());
|
||||
// Record does not exists. add
|
||||
} else if (list.size() == 1) {
|
||||
tempTarget = list.get(0);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating TempTarget record in database: " + trJson.toString());
|
||||
} else {
|
||||
log.error("Somthing went wrong");
|
||||
return;
|
||||
}
|
||||
tempTarget.date = trJson.getLong("mills");
|
||||
tempTarget.durationInMinutes = trJson.getInt("duration");
|
||||
tempTarget.low = NSProfile.toMgdl(trJson.getDouble("targetBottom"), units);
|
||||
tempTarget.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
|
||||
tempTarget.reason = trJson.getString("reason");
|
||||
tempTarget._id = trJson.getString("_id");
|
||||
createIfNotExists(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteTempTargetById(String _id) {
|
||||
try {
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = null;
|
||||
queryBuilder = getDaoTempTargets().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", _id);
|
||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||
List<TempTarget> list = getDaoTempTargets().query(preparedQuery);
|
||||
|
||||
if (list.size() == 1) {
|
||||
TempTarget record = list.get(0);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Removing TempTarget record from database: " + record.log());
|
||||
getDaoTempTargets().delete(record);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} else {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("TempTarget not found database: " + _id);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------- DanaRHistory handling --------------------
|
||||
|
||||
public void createIfNotExists(DanaRHistoryRecord record) {
|
||||
try {
|
||||
getDaoDanaRHistory().createIfNotExists(record);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<DanaRHistoryRecord> getDanaRHistoryRecordsByType(byte type) {
|
||||
List<DanaRHistoryRecord> historyList;
|
||||
try {
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = getDaoDanaRHistory().queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = getDaoDanaRHistory().query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
return historyList;
|
||||
}
|
||||
|
||||
public void updateDanaRHistoryRecordId(JSONObject trJson) {
|
||||
try {
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = getDaoDanaRHistory().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("bytes", trJson.get(DanaRNSHistorySync.DANARSIGNATURE));
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
List<DanaRHistoryRecord> list = getDaoDanaRHistory().query(preparedQuery);
|
||||
if (list.size() == 0) {
|
||||
// Record does not exists. Ignore
|
||||
} else if (list.size() == 1) {
|
||||
DanaRHistoryRecord record = list.get(0);
|
||||
if (record._id == null || !record._id.equals(trJson.getString("_id"))) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating _id in DanaR history database: " + trJson.getString("_id"));
|
||||
record._id = trJson.getString("_id");
|
||||
getDaoDanaRHistory().update(record);
|
||||
} else {
|
||||
// already set
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
|||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.PlusMinusEditText;
|
||||
import info.nightscout.utils.SP;
|
||||
|
@ -659,13 +658,11 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
tempTarget.low = 0;
|
||||
tempTarget.high = 0;
|
||||
}
|
||||
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
|
||||
log.debug("Creating new TempTarget db record: " + tempTarget.log());
|
||||
dao.createIfNotExists(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
MainApp.getDbHelper().createIfNotExists(tempTarget);
|
||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
||||
} catch (JSONException | SQLException e) {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class UploadQueue {
|
|||
String result = "";
|
||||
CloseableIterator<DbRequest> iterator = null;
|
||||
try {
|
||||
iterator = MainApp.getDbHelper().getDaoDbRequest().closeableIterator();
|
||||
iterator = MainApp.getDbHelper().getDbRequestInterator();
|
||||
try {
|
||||
while (iterator.hasNext()) {
|
||||
DbRequest dbr = iterator.next();
|
||||
|
|
|
@ -653,7 +653,7 @@ public class NSClientService extends Service {
|
|||
|
||||
CloseableIterator<DbRequest> iterator = null;
|
||||
try {
|
||||
iterator = MainApp.getDbHelper().getDaoDbRequest().closeableIterator();
|
||||
iterator = MainApp.getDbHelper().getDbRequestInterator();
|
||||
try {
|
||||
while (iterator.hasNext()) {
|
||||
DbRequest dbr = iterator.next();
|
||||
|
|
|
@ -42,12 +42,11 @@ import java.util.Date;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
|
@ -381,7 +380,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
else editBg.setStep(0.1d);
|
||||
|
||||
// Set BG if not old
|
||||
BgReading lastBg = GlucoseStatus.actualBg();
|
||||
BgReading lastBg = DatabaseHelper.actualBg();
|
||||
|
||||
if (lastBg != null) {
|
||||
Double lastBgValue = lastBg.valueToUnits(units);
|
||||
|
|
|
@ -66,6 +66,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
|
|||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.TempExBasal;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
|
@ -546,7 +547,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
void onClickQuickwizard() {
|
||||
final BgReading actualBg = GlucoseStatus.actualBg();
|
||||
final BgReading actualBg = DatabaseHelper.actualBg();
|
||||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||
return;
|
||||
final NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||
|
@ -794,8 +795,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
public void updateGUI(String from) {
|
||||
log.debug("updateGUI entered from: " + from);
|
||||
updateNotifications();
|
||||
BgReading actualBG = GlucoseStatus.actualBg();
|
||||
BgReading lastBG = GlucoseStatus.lastBg();
|
||||
BgReading actualBG = DatabaseHelper.actualBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
|
||||
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null || MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet
|
||||
pumpStatusView.setText(R.string.noprofileset);
|
||||
|
@ -891,7 +892,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
// **** Calibration button ****
|
||||
if (MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE) && profile != null && GlucoseStatus.actualBg() != null) {
|
||||
if (MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE) && profile != null && DatabaseHelper.actualBg() != null) {
|
||||
calibrationButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
calibrationButton.setVisibility(View.GONE);
|
||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.TempExBasal;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
|
@ -121,7 +122,7 @@ public class PersistentNotificationPlugin implements PluginBase{
|
|||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
||||
|
||||
BgReading lastBG = GlucoseStatus.lastBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
|
||||
if(profile != null && lastBG != null) {
|
||||
|
|
|
@ -389,19 +389,8 @@ public class DanaRHistoryActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -341,19 +341,8 @@ public class DanaRStatsActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(10L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -143,12 +143,7 @@ public class MsgHistoryAll extends MessageBase {
|
|||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
daoHistoryRecords.createIfNotExists(danaRHistoryRecord);
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
MainApp.getDbHelper().createIfNotExists(danaRHistoryRecord);
|
||||
|
||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
||||
ev.message += " " + messageType;
|
||||
|
|
|
@ -388,19 +388,8 @@ public class DanaRHistoryActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -341,19 +341,8 @@ public class DanaRStatsActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(10L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -389,19 +389,8 @@ public class DanaRHistoryActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -341,19 +341,8 @@ public class DanaRStatsActivity extends Activity {
|
|||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(10L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
|
|||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
|
@ -231,8 +232,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (splited.length > 0) {
|
||||
switch (splited[0].toUpperCase()) {
|
||||
case "BG":
|
||||
BgReading actualBG = GlucoseStatus.actualBg();
|
||||
BgReading lastBG = GlucoseStatus.lastBg();
|
||||
BgReading actualBG = DatabaseHelper.actualBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
|
||||
if (ConfigBuilderPlugin.getActiveProfile() == null || ConfigBuilderPlugin.getActiveProfile().getProfile() == null) {
|
||||
reply = MainApp.sResources.getString(R.string.noprofile);
|
||||
|
|
|
@ -152,13 +152,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
|
|||
if (_id != null && !_id.equals("")) {
|
||||
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||
}
|
||||
try {
|
||||
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
|
||||
daoTempTargets.delete(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.getDbHelper().delete(tempTarget);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
|
||||
|
|
|
@ -4,9 +4,6 @@ import android.os.Handler;
|
|||
import android.os.HandlerThread;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -15,9 +12,9 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
|
@ -25,7 +22,6 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
|
|||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
import info.nightscout.utils.BolusWizard;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
@ -46,13 +42,14 @@ public class ActionStringHandler {
|
|||
private static BolusWizard lastBolusWizard = null;
|
||||
|
||||
private static HandlerThread handlerThread = new HandlerThread(FillDialog.class.getSimpleName());
|
||||
|
||||
static {
|
||||
handlerThread.start();
|
||||
}
|
||||
|
||||
public synchronized static void handleInitiate(String actionstring){
|
||||
public synchronized static void handleInitiate(String actionstring) {
|
||||
|
||||
if(!BuildConfig.WEAR_CONTROL) return;
|
||||
if (!BuildConfig.WEAR_CONTROL) return;
|
||||
|
||||
|
||||
lastBolusWizard = null;
|
||||
|
@ -123,19 +120,19 @@ public class ActionStringHandler {
|
|||
sendError("No profile found!");
|
||||
return;
|
||||
}
|
||||
if(profile.getUnits().equals(Constants.MGDL) != isMGDL){
|
||||
if (profile.getUnits().equals(Constants.MGDL) != isMGDL) {
|
||||
sendError("Different units used on watch and phone!");
|
||||
return;
|
||||
}
|
||||
|
||||
int duration = SafeParse.stringToInt(act[2]);
|
||||
if (duration == 0){
|
||||
if (duration == 0) {
|
||||
rMessage += "Zero-Temp-Target - cancelling running Temp-Targets?";
|
||||
rAction = "temptarget true 0 0 0";
|
||||
} else {
|
||||
double low = SafeParse.stringToDouble(act[3]);
|
||||
double high = SafeParse.stringToDouble(act[4]);
|
||||
if(!isMGDL){
|
||||
if (!isMGDL) {
|
||||
low *= Constants.MMOLL_TO_MGDL;
|
||||
high *= Constants.MMOLL_TO_MGDL;
|
||||
}
|
||||
|
@ -147,7 +144,7 @@ public class ActionStringHandler {
|
|||
sendError("Max-BG out of range!");
|
||||
return;
|
||||
}
|
||||
rMessage += "Temptarget:\nMin: " + act[3] + "\nMax: " + act[4] + "\nDuration: " + act[2];
|
||||
rMessage += "Temptarget:\nMin: " + act[3] + "\nMax: " + act[4] + "\nDuration: " + act[2];
|
||||
rAction = actionstring;
|
||||
|
||||
}
|
||||
|
@ -156,14 +153,14 @@ public class ActionStringHandler {
|
|||
////////////////////////////////////////////// STATUS
|
||||
rTitle = "STATUS";
|
||||
rAction = "statusmessage";
|
||||
if("pump".equals(act[1])){
|
||||
if ("pump".equals(act[1])) {
|
||||
rTitle += " PUMP";
|
||||
rMessage = getPumpStatus();
|
||||
} else if("loop".equals(act[1])){
|
||||
} else if ("loop".equals(act[1])) {
|
||||
rTitle += " LOOP";
|
||||
rMessage = getLoopStatus();
|
||||
|
||||
} else if("targets".equals(act[1])){
|
||||
} else if ("targets".equals(act[1])) {
|
||||
rTitle += " TARGETS";
|
||||
rMessage = getTargetsStatus();
|
||||
}
|
||||
|
@ -173,8 +170,9 @@ public class ActionStringHandler {
|
|||
Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]);
|
||||
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbsBeforeConstraints);
|
||||
|
||||
if(carbsAfterConstraints - carbsBeforeConstraints !=0){
|
||||
sendError("Carb constraint violation!"); return;
|
||||
if (carbsAfterConstraints - carbsBeforeConstraints != 0) {
|
||||
sendError("Carb constraint violation!");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean useBG = Boolean.parseBoolean(act[2]);
|
||||
|
@ -183,31 +181,33 @@ public class ActionStringHandler {
|
|||
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null) {
|
||||
sendError("No profile found!"); return;
|
||||
sendError("No profile found!");
|
||||
return;
|
||||
}
|
||||
|
||||
BgReading bgReading = GlucoseStatus.actualBg();
|
||||
if(bgReading==null && useBG){
|
||||
sendError("No recent BG to base calculation on!"); return;
|
||||
BgReading bgReading = DatabaseHelper.actualBg();
|
||||
if (bgReading == null && useBG) {
|
||||
sendError("No recent BG to base calculation on!");
|
||||
return;
|
||||
}
|
||||
DecimalFormat format = new DecimalFormat("0.00");
|
||||
BolusWizard bolusWizard = new BolusWizard();
|
||||
bolusWizard.doCalc(profile.getDefaultProfile(), carbsAfterConstraints, 0d, useBG?bgReading.valueToUnits(profile.getUnits()):0d, 0d, useBolusIOB, useBasalIOB, false, false);
|
||||
bolusWizard.doCalc(profile.getDefaultProfile(), carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, useBolusIOB, useBasalIOB, false, false);
|
||||
|
||||
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin);
|
||||
if(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin !=0){
|
||||
if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) {
|
||||
sendError("Insulin contraint violation!" +
|
||||
"\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) +"!");
|
||||
"\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) + "!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
double insulin = bolusWizard.calculatedTotalInsulin;
|
||||
if(bolusWizard.calculatedTotalInsulin < 0) {
|
||||
if (bolusWizard.calculatedTotalInsulin < 0) {
|
||||
bolusWizard.calculatedTotalInsulin = 0d;
|
||||
}
|
||||
|
||||
if(bolusWizard.calculatedTotalInsulin <=0 && bolusWizard.carbs <=0){
|
||||
if (bolusWizard.calculatedTotalInsulin <= 0 && bolusWizard.carbs <= 0) {
|
||||
rAction = "info";
|
||||
rTitle = "INFO";
|
||||
} else {
|
||||
|
@ -216,11 +216,13 @@ public class ActionStringHandler {
|
|||
rMessage += "Carbs: " + bolusWizard.carbs + "g";
|
||||
rMessage += "\nBolus: " + format.format(bolusWizard.calculatedTotalInsulin) + "U";
|
||||
rMessage += "\n_____________";
|
||||
rMessage += "\nCalc (IC:" + DecimalFormatter.to1Decimal(bolusWizard.ic) + ", " + "ISF:" + DecimalFormatter.to1Decimal(bolusWizard.sens) + "): ";
|
||||
rMessage += "\nCalc (IC:" + DecimalFormatter.to1Decimal(bolusWizard.ic) + ", " + "ISF:" + DecimalFormatter.to1Decimal(bolusWizard.sens) + "): ";
|
||||
rMessage += "\nFrom Carbs: " + format.format(bolusWizard.insulinFromCarbs) + "U";
|
||||
if(useBG)rMessage += "\nFrom BG: " + format.format(bolusWizard.insulinFromBG) + "U";
|
||||
if(useBolusIOB)rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
||||
if(useBasalIOB)rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
||||
if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.insulinFromBG) + "U";
|
||||
if (useBolusIOB)
|
||||
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
||||
if (useBasalIOB)
|
||||
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
||||
|
||||
lastBolusWizard = bolusWizard;
|
||||
|
||||
|
@ -242,25 +244,24 @@ public class ActionStringHandler {
|
|||
String ret = "";
|
||||
// decide if enabled/disabled closed/open; what Plugin as APS?
|
||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
if(activeloop != null && activeloop.isEnabled(activeloop.getType())) {
|
||||
if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
|
||||
if (MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||
ret += "CLOSED LOOP\n";
|
||||
} else {
|
||||
ret += "OPEN LOOP\n";
|
||||
}
|
||||
final APSInterface aps = MainApp.getConfigBuilder().getActiveAPS();
|
||||
ret += "APS: " + ((aps==null)?"NO APS SELECTED!":((PluginBase) aps).getName());
|
||||
if(activeloop.lastRun != null){
|
||||
if(activeloop.lastRun.lastAPSRun != null)
|
||||
ret += "APS: " + ((aps == null) ? "NO APS SELECTED!" : ((PluginBase) aps).getName());
|
||||
if (activeloop.lastRun != null) {
|
||||
if (activeloop.lastRun.lastAPSRun != null)
|
||||
ret += "\nLast Run: " + DateUtil.timeString(activeloop.lastRun.lastAPSRun);
|
||||
|
||||
if(activeloop.lastRun.lastEnact != null)
|
||||
if (activeloop.lastRun.lastEnact != null)
|
||||
ret += "\nLast Enact: " + DateUtil.timeString(activeloop.lastRun.lastEnact);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
ret += "LOOP DISABLED\n";
|
||||
}
|
||||
|
@ -271,11 +272,11 @@ public class ActionStringHandler {
|
|||
@NonNull
|
||||
private static String getTargetsStatus() {
|
||||
String ret = "";
|
||||
if (!Config.APS){
|
||||
if (!Config.APS) {
|
||||
return "Targets only apply in APS mode!";
|
||||
}
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null){
|
||||
if (profile == null) {
|
||||
return "No profile set :(";
|
||||
}
|
||||
|
||||
|
@ -306,9 +307,9 @@ public class ActionStringHandler {
|
|||
}
|
||||
|
||||
|
||||
public synchronized static void handleConfirmation(String actionString){
|
||||
public synchronized static void handleConfirmation(String actionString) {
|
||||
|
||||
if(!BuildConfig.WEAR_CONTROL) return;
|
||||
if (!BuildConfig.WEAR_CONTROL) return;
|
||||
|
||||
|
||||
//Guard from old or duplicate confirmations
|
||||
|
@ -320,10 +321,10 @@ public class ActionStringHandler {
|
|||
// do the parsing, check constraints and enact!
|
||||
String[] act = actionString.split("\\s+");
|
||||
|
||||
if ("fill".equals(act[0])){
|
||||
if ("fill".equals(act[0])) {
|
||||
Double amount = SafeParse.stringToDouble(act[1]);
|
||||
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
if(amount - insulinAfterConstraints != 0){
|
||||
if (amount - insulinAfterConstraints != 0) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance(), "aborting: previously applied constraint changed");
|
||||
sendError("aborting: previously applied constraint changed");
|
||||
return;
|
||||
|
@ -334,12 +335,12 @@ public class ActionStringHandler {
|
|||
double low = SafeParse.stringToDouble(act[3]);
|
||||
double high = SafeParse.stringToDouble(act[4]);
|
||||
boolean isMGDL = Boolean.parseBoolean(act[1]);
|
||||
if(!isMGDL){
|
||||
if (!isMGDL) {
|
||||
low *= Constants.MMOLL_TO_MGDL;
|
||||
high *= Constants.MMOLL_TO_MGDL;
|
||||
}
|
||||
generateTempTarget(duration, low, high);
|
||||
} else if ("wizard".equals(act[0])){
|
||||
} else if ("wizard".equals(act[0])) {
|
||||
//use last calculation as confirmed string matches
|
||||
|
||||
doBolus(lastBolusWizard.calculatedTotalInsulin, lastBolusWizard.carbs);
|
||||
|
@ -357,24 +358,17 @@ public class ActionStringHandler {
|
|||
tempTarget.date = new Date().getTime();
|
||||
tempTarget.durationInMinutes = duration;
|
||||
tempTarget.reason = "WearPlugin";
|
||||
if(tempTarget.durationInMinutes != 0) {
|
||||
if (tempTarget.durationInMinutes != 0) {
|
||||
tempTarget.low = low;
|
||||
tempTarget.high = high;
|
||||
} else {
|
||||
tempTarget.low = 0;
|
||||
tempTarget.high = 0;
|
||||
}
|
||||
Dao<TempTarget, Long> dao = null;
|
||||
try {
|
||||
dao = MainApp.getDbHelper().getDaoTempTargets();
|
||||
dao.createIfNotExists(tempTarget);
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
MainApp.getDbHelper().createIfNotExists(tempTarget);
|
||||
|
||||
//TODO: Nightscout-Treatment for Temp-Target!
|
||||
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//TODO: Nightscout-Treatment for Temp-Target!
|
||||
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
}
|
||||
|
||||
private static void doFillBolus(final Double amount) {
|
||||
|
@ -385,7 +379,7 @@ public class ActionStringHandler {
|
|||
public void run() {
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, 0, null, false);
|
||||
if (!result.success) {
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
"\n" +
|
||||
result.comment);
|
||||
}
|
||||
|
@ -401,7 +395,7 @@ public class ActionStringHandler {
|
|||
public void run() {
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, carbs, null, true);
|
||||
if (!result.success) {
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
"\n" +
|
||||
result.comment);
|
||||
}
|
||||
|
@ -409,7 +403,7 @@ public class ActionStringHandler {
|
|||
});
|
||||
}
|
||||
|
||||
private synchronized static void sendError(String errormessage){
|
||||
private synchronized static void sendError(String errormessage) {
|
||||
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation("ERROR", errormessage, "error");
|
||||
lastSentTimestamp = System.currentTimeMillis();
|
||||
lastConfirmActionString = null;
|
||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.TempExBasal;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -187,7 +188,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
private void sendData() {
|
||||
|
||||
BgReading lastBG = GlucoseStatus.lastBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
if (lastBG != null) {
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
|
||||
|
@ -295,7 +296,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
private void resendData() {
|
||||
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
|
||||
long startTime = System.currentTimeMillis() - (long)(60000 * 60 * 5.5);
|
||||
BgReading last_bg = GlucoseStatus.lastBg();
|
||||
BgReading last_bg = DatabaseHelper.lastBg();
|
||||
|
||||
if (last_bg == null) return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue