sync of treatments, tempbasals, extended tested and working
This commit is contained in:
parent
8db1bd5ae5
commit
771fbdc303
14 changed files with 580 additions and 98 deletions
|
@ -401,7 +401,9 @@ public class DataService extends IntentService {
|
||||||
JSONObject trJson = new JSONObject(trstring);
|
JSONObject trJson = new JSONObject(trstring);
|
||||||
String _id = trJson.getString("_id");
|
String _id = trJson.getString("_id");
|
||||||
MainApp.getDbHelper().deleteTreatmentById(_id);
|
MainApp.getDbHelper().deleteTreatmentById(_id);
|
||||||
handleRemoveTempTargetRecord(trJson);
|
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundles.containsKey("treatments")) {
|
if (bundles.containsKey("treatments")) {
|
||||||
|
@ -411,7 +413,9 @@ public class DataService extends IntentService {
|
||||||
JSONObject trJson = jsonArray.getJSONObject(i);
|
JSONObject trJson = jsonArray.getJSONObject(i);
|
||||||
String _id = trJson.getString("_id");
|
String _id = trJson.getString("_id");
|
||||||
MainApp.getDbHelper().deleteTreatmentById(_id);
|
MainApp.getDbHelper().deleteTreatmentById(_id);
|
||||||
handleRemoveTempTargetRecord(trJson);
|
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -468,9 +472,10 @@ public class DataService extends IntentService {
|
||||||
handleDanaRHistoryRecords(trJson); // update record _id in history
|
handleDanaRHistoryRecords(trJson); // update record _id in history
|
||||||
handleAddChangeTempTargetRecord(trJson);
|
handleAddChangeTempTargetRecord(trJson);
|
||||||
handleAddChangeTempBasalRecord(trJson);
|
handleAddChangeTempBasalRecord(trJson);
|
||||||
|
handleAddChangeExtendedBolusRecord(trJson);
|
||||||
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("ADD: Uninterested treatment: " + trstring);
|
log.debug("Ignoring non insulin/carbs record: " + trstring);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,21 +593,6 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"_id": "58795998aa86647ba4d68ce7",
|
|
||||||
"enteredBy": "",
|
|
||||||
"eventType": "Temporary Target",
|
|
||||||
"reason": "Eating Soon",
|
|
||||||
"targetTop": 80,
|
|
||||||
"targetBottom": 80,
|
|
||||||
"duration": 120,
|
|
||||||
"created_at": "2017-01-13T22:50:00.782Z",
|
|
||||||
"carbs": null,
|
|
||||||
"insulin": null
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temporary Target")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temporary Target")) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
|
@ -611,31 +601,6 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoveTempTargetRecord(JSONObject trJson) {
|
|
||||||
if (trJson.has("_id")) {
|
|
||||||
try {
|
|
||||||
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"_id": "59232e1ddd032d04218dab00",
|
|
||||||
"eventType": "Temp Basal",
|
|
||||||
"duration": 60,
|
|
||||||
"percent": -50,
|
|
||||||
"created_at": "2017-05-22T18:29:57Z",
|
|
||||||
"enteredBy": "AndroidAPS",
|
|
||||||
"notes": "Basal Temp Start 50% 60.0 min",
|
|
||||||
"NSCLIENT_ID": 1495477797863,
|
|
||||||
"mills": 1495477797000,
|
|
||||||
"mgdl": 194.5,
|
|
||||||
"endmills": 1495481397000
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public void handleAddChangeTempBasalRecord(JSONObject trJson) throws JSONException, SQLException {
|
public void handleAddChangeTempBasalRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temp Basal")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temp Basal")) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
|
@ -644,13 +609,11 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoveTempBasalRecord(JSONObject trJson) {
|
public void handleAddChangeExtendedBolusRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("_id")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals("Combo Bolus")) {
|
||||||
try {
|
if (Config.logIncommingData)
|
||||||
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
log.debug("Processing Extended Bolus record: " + trJson.toString());
|
||||||
} catch (JSONException e) {
|
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(trJson);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||||
//DbRequests can be cleared from NSClient fragment
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
||||||
|
@ -171,6 +170,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
scheduleBgChange(); // trigger refresh
|
scheduleBgChange(); // trigger refresh
|
||||||
|
scheduleTemporaryBasalChange();
|
||||||
|
scheduleTreatmentChange();
|
||||||
|
scheduleExtendedBolusChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTreatments() {
|
public void resetTreatments() {
|
||||||
|
@ -246,6 +248,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
// ------------------- BgReading handling -----------------------
|
// ------------------- BgReading handling -----------------------
|
||||||
|
|
||||||
public void createIfNotExists(BgReading bgReading) {
|
public void createIfNotExists(BgReading bgReading) {
|
||||||
|
bgReading.date = bgReading.date - bgReading.date % 1000;
|
||||||
try {
|
try {
|
||||||
getDaoBgReadings().createIfNotExists(bgReading);
|
getDaoBgReadings().createIfNotExists(bgReading);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -459,21 +462,19 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteTreatmentById(String _id) {
|
public int deleteTreatmentById(String _id) {
|
||||||
Treatment stored = findTreatmentById(_id);
|
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
if (stored != null) {
|
try {
|
||||||
log.debug("REMOVE: Existing treatment (removing): " + _id);
|
Treatment stored = findTreatmentById(_id);
|
||||||
try {
|
if (stored != null) {
|
||||||
|
log.debug("Removing TempTarget record from database: " + stored.log());
|
||||||
removed = getDaoTreatments().delete(stored);
|
removed = getDaoTreatments().delete(stored);
|
||||||
} catch (SQLException e) {
|
latestTreatmentChange = stored.date;
|
||||||
e.printStackTrace();
|
scheduleTreatmentChange();
|
||||||
|
} else {
|
||||||
|
log.debug("Treatment not found database: " + _id);
|
||||||
}
|
}
|
||||||
if (Config.logIncommingData)
|
} catch (SQLException e) {
|
||||||
log.debug("Records removed: " + removed);
|
e.printStackTrace();
|
||||||
latestTreatmentChange = stored.date;
|
|
||||||
scheduleTreatmentChange();
|
|
||||||
} else {
|
|
||||||
log.debug("REMOVE: Not stored treatment (ignoring): " + _id);
|
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
@ -581,9 +582,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return new ArrayList<TempTarget>();
|
return new ArrayList<TempTarget>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createIfNotExists(TempTarget tempTarget) {
|
public void createOrUpdate(TempTarget tempTarget) {
|
||||||
|
tempTarget.date = tempTarget.date - tempTarget.date % 1000;
|
||||||
try {
|
try {
|
||||||
getDaoTempTargets().createIfNotExists(tempTarget);
|
getDaoTempTargets().createOrUpdate(tempTarget);
|
||||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -599,6 +601,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"_id": "58795998aa86647ba4d68ce7",
|
||||||
|
"enteredBy": "",
|
||||||
|
"eventType": "Temporary Target",
|
||||||
|
"reason": "Eating Soon",
|
||||||
|
"targetTop": 80,
|
||||||
|
"targetBottom": 80,
|
||||||
|
"duration": 120,
|
||||||
|
"created_at": "2017-01-13T22:50:00.782Z",
|
||||||
|
"carbs": null,
|
||||||
|
"insulin": null
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public void createTemptargetFromJsonIfNotExists(JSONObject trJson) {
|
public void createTemptargetFromJsonIfNotExists(JSONObject trJson) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<TempTarget, Long> queryBuilder = null;
|
QueryBuilder<TempTarget, Long> queryBuilder = null;
|
||||||
|
@ -621,7 +638,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Updating TempTarget record in database: " + trJson.toString());
|
log.debug("Updating TempTarget record in database: " + trJson.toString());
|
||||||
} else {
|
} else {
|
||||||
log.error("Somthing went wrong");
|
log.error("Something went wrong");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempTarget.date = trJson.getLong("mills");
|
tempTarget.date = trJson.getLong("mills");
|
||||||
|
@ -630,7 +647,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
tempTarget.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
|
tempTarget.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
|
||||||
tempTarget.reason = trJson.getString("reason");
|
tempTarget.reason = trJson.getString("reason");
|
||||||
tempTarget._id = trJson.getString("_id");
|
tempTarget._id = trJson.getString("_id");
|
||||||
createIfNotExists(tempTarget);
|
createOrUpdate(tempTarget);
|
||||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -641,8 +658,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
public void deleteTempTargetById(String _id) {
|
public void deleteTempTargetById(String _id) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<TempTarget, Long> queryBuilder = null;
|
QueryBuilder<TempTarget, Long> queryBuilder = getDaoTempTargets().queryBuilder();
|
||||||
queryBuilder = getDaoTempTargets().queryBuilder();
|
|
||||||
Where where = queryBuilder.where();
|
Where where = queryBuilder.where();
|
||||||
where.eq("_id", _id);
|
where.eq("_id", _id);
|
||||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||||
|
@ -665,9 +681,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
// ----------------- DanaRHistory handling --------------------
|
// ----------------- DanaRHistory handling --------------------
|
||||||
|
|
||||||
public void createIfNotExists(DanaRHistoryRecord record) {
|
public void createOrUpdate(DanaRHistoryRecord record) {
|
||||||
try {
|
try {
|
||||||
getDaoDanaRHistory().createIfNotExists(record);
|
getDaoDanaRHistory().createOrUpdate(record);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -731,10 +747,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createIfNotExists(TemporaryBasal tempBasal) {
|
public void createOrUpdate(TemporaryBasal tempBasal) {
|
||||||
tempBasal.date = tempBasal.date - tempBasal.date % 1000;
|
tempBasal.date = tempBasal.date - tempBasal.date % 1000;
|
||||||
try {
|
try {
|
||||||
getDaoTemporaryBasal().createIfNotExists(tempBasal);
|
getDaoTemporaryBasal().createOrUpdate(tempBasal);
|
||||||
latestTreatmentChange = tempBasal.date;
|
latestTreatmentChange = tempBasal.date;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -785,6 +801,22 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"_id": "59232e1ddd032d04218dab00",
|
||||||
|
"eventType": "Temp Basal",
|
||||||
|
"duration": 60,
|
||||||
|
"percent": -50,
|
||||||
|
"created_at": "2017-05-22T18:29:57Z",
|
||||||
|
"enteredBy": "AndroidAPS",
|
||||||
|
"notes": "Basal Temp Start 50% 60.0 min",
|
||||||
|
"NSCLIENT_ID": 1495477797863,
|
||||||
|
"mills": 1495477797000,
|
||||||
|
"mgdl": 194.5,
|
||||||
|
"endmills": 1495481397000
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public void createTempBasalFromJsonIfNotExists(JSONObject trJson) {
|
public void createTempBasalFromJsonIfNotExists(JSONObject trJson) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<TemporaryBasal, Long> queryBuilder = null;
|
QueryBuilder<TemporaryBasal, Long> queryBuilder = null;
|
||||||
|
@ -793,9 +825,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
||||||
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||||
List<TemporaryBasal> list = getDaoTemporaryBasal().query(preparedQuery);
|
List<TemporaryBasal> list = getDaoTemporaryBasal().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();
|
|
||||||
TemporaryBasal tempBasal;
|
TemporaryBasal tempBasal;
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
tempBasal = new TemporaryBasal();
|
tempBasal = new TemporaryBasal();
|
||||||
|
@ -808,7 +837,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Updating TemporaryBasal record in database: " + trJson.toString());
|
log.debug("Updating TemporaryBasal record in database: " + trJson.toString());
|
||||||
} else {
|
} else {
|
||||||
log.error("Somthing went wrong");
|
log.error("Something went wrong");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempBasal.date = trJson.getLong("mills");
|
tempBasal.date = trJson.getLong("mills");
|
||||||
|
@ -824,7 +853,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
tempBasal.isAbsolute = true;
|
tempBasal.isAbsolute = true;
|
||||||
}
|
}
|
||||||
tempBasal._id = trJson.getString("_id");
|
tempBasal._id = trJson.getString("_id");
|
||||||
createIfNotExists(tempBasal);
|
createOrUpdate(tempBasal);
|
||||||
|
scheduleTemporaryBasalChange();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -849,7 +879,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||||
} else {
|
} else {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("TempTarget not found database: " + _id);
|
log.debug("TempBasal not found database: " + _id);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -870,9 +900,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(ExtendedBolus extendedBolus) {
|
public void createOrUpdate(ExtendedBolus extendedBolus) {
|
||||||
|
extendedBolus.date = extendedBolus.date - extendedBolus.date % 1000;
|
||||||
try {
|
try {
|
||||||
getDaoExtendedBolus().create(extendedBolus);
|
getDaoExtendedBolus().createOrUpdate(extendedBolus);
|
||||||
latestTreatmentChange = extendedBolus.date;
|
latestTreatmentChange = extendedBolus.date;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -906,11 +937,89 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return new ArrayList<ExtendedBolus>();
|
return new ArrayList<ExtendedBolus>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteExtendedBolusById(String _id) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
|
||||||
|
queryBuilder = getDaoExtendedBolus().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", _id);
|
||||||
|
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
|
||||||
|
|
||||||
|
if (list.size() == 1) {
|
||||||
|
ExtendedBolus record = list.get(0);
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Removing ExtendedBolus record from database: " + record.log());
|
||||||
|
getDaoExtendedBolus().delete(record);
|
||||||
|
scheduleExtendedBolusChange();
|
||||||
|
} else {
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("ExtendedBolus not found database: " + _id);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"_id": "5924898d577eb0880e355337",
|
||||||
|
"eventType": "Combo Bolus",
|
||||||
|
"duration": 120,
|
||||||
|
"splitNow": 0,
|
||||||
|
"splitExt": 100,
|
||||||
|
"enteredinsulin": 1,
|
||||||
|
"relative": 1,
|
||||||
|
"created_at": "2017-05-23T19:12:14Z",
|
||||||
|
"enteredBy": "AndroidAPS",
|
||||||
|
"NSCLIENT_ID": 1495566734628,
|
||||||
|
"mills": 1495566734000,
|
||||||
|
"mgdl": 106
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void createExtendedBolusFromJsonIfNotExists(JSONObject trJson) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
|
||||||
|
queryBuilder = getDaoExtendedBolus().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
||||||
|
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
|
||||||
|
ExtendedBolus extendedBolus;
|
||||||
|
if (list.size() == 0) {
|
||||||
|
extendedBolus = new ExtendedBolus();
|
||||||
|
extendedBolus.source = Source.NIGHTSCOUT;
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Adding ExtendedBolus record to database: " + trJson.toString());
|
||||||
|
// Record does not exists. add
|
||||||
|
} else if (list.size() == 1) {
|
||||||
|
extendedBolus = list.get(0);
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Updating ExtendedBolus record in database: " + trJson.toString());
|
||||||
|
} else {
|
||||||
|
log.error("Something went wrong");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
extendedBolus.date = trJson.getLong("mills");
|
||||||
|
extendedBolus.durationInMinutes = trJson.getInt("duration");
|
||||||
|
extendedBolus.insulin = trJson.getDouble("relative");
|
||||||
|
extendedBolus._id = trJson.getString("_id");
|
||||||
|
createOrUpdate(extendedBolus);
|
||||||
|
scheduleExtendedBolusChange();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static public void scheduleExtendedBolusChange() {
|
static public void scheduleExtendedBolusChange() {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
MainApp.bus().post(new EventExtendedBolusChange());
|
MainApp.bus().post(new EventExtendedBolusChange());
|
||||||
scheduledExtendedBolusPost = null;
|
scheduledExtendedBolusPost = null;
|
||||||
|
log.debug("Firing EventExtendedBolusChange");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// prepare task for execution in 1 sec
|
// prepare task for execution in 1 sec
|
||||||
|
|
|
@ -126,6 +126,10 @@ public class ExtendedBolus implements Interval {
|
||||||
return Round.roundTo(insulin / durationInMinutes * 60, 0.01);
|
return Round.roundTo(insulin / durationInMinutes * 60, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double insulinSoFar() {
|
||||||
|
return absoluteRate() * getRealDuration() / 60d;
|
||||||
|
}
|
||||||
|
|
||||||
public IobTotal iobCalc(long time) {
|
public IobTotal iobCalc(long time) {
|
||||||
IobTotal result = new IobTotal(time);
|
IobTotal result = new IobTotal(time);
|
||||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
|
|
|
@ -26,7 +26,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.j256.ormlite.dao.Dao;
|
|
||||||
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
||||||
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
|
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
|
||||||
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
|
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
|
||||||
|
@ -36,7 +35,6 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -659,7 +657,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
tempTarget.high = 0;
|
tempTarget.high = 0;
|
||||||
}
|
}
|
||||||
log.debug("Creating new TempTarget db record: " + tempTarget.log());
|
log.debug("Creating new TempTarget db record: " + tempTarget.log());
|
||||||
MainApp.getDbHelper().createIfNotExists(tempTarget);
|
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
||||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaR.comm;
|
package info.nightscout.androidaps.plugins.PumpDanaR.comm;
|
||||||
|
|
||||||
import com.j256.ormlite.dao.Dao;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -143,7 +140,7 @@ public class MsgHistoryAll extends MessageBase {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(danaRHistoryRecord);
|
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
||||||
|
|
||||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
||||||
ev.message += " " + messageType;
|
ev.message += " " + messageType;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsBolusFragment;
|
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsBolusFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsExtendedBolusesFragment;
|
||||||
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsTemporaryBasalsFragment;
|
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsTemporaryBasalsFragment;
|
||||||
|
|
||||||
public class TreatmentsFromHistoryFragment extends Fragment implements View.OnClickListener {
|
public class TreatmentsFromHistoryFragment extends Fragment implements View.OnClickListener {
|
||||||
|
@ -27,6 +28,7 @@ public class TreatmentsFromHistoryFragment extends Fragment implements View.OnCl
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
TextView treatmentsTab;
|
TextView treatmentsTab;
|
||||||
|
TextView extendedBolusesTab;
|
||||||
TextView tempBasalsTab;
|
TextView tempBasalsTab;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,8 +37,10 @@ public class TreatmentsFromHistoryFragment extends Fragment implements View.OnCl
|
||||||
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
|
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
|
||||||
|
|
||||||
treatmentsTab = (TextView) view.findViewById(R.id.treatments_treatments);
|
treatmentsTab = (TextView) view.findViewById(R.id.treatments_treatments);
|
||||||
|
extendedBolusesTab = (TextView) view.findViewById(R.id.treatments_extendedboluses);
|
||||||
tempBasalsTab = (TextView) view.findViewById(R.id.treatments_tempbasals);
|
tempBasalsTab = (TextView) view.findViewById(R.id.treatments_tempbasals);
|
||||||
treatmentsTab.setOnClickListener(this);
|
treatmentsTab.setOnClickListener(this);
|
||||||
|
extendedBolusesTab.setOnClickListener(this);
|
||||||
tempBasalsTab.setOnClickListener(this);
|
tempBasalsTab.setOnClickListener(this);
|
||||||
context = getContext();
|
context = getContext();
|
||||||
|
|
||||||
|
@ -52,6 +56,9 @@ public class TreatmentsFromHistoryFragment extends Fragment implements View.OnCl
|
||||||
case R.id.treatments_treatments:
|
case R.id.treatments_treatments:
|
||||||
setFragment(new TreatmentsBolusFragment());
|
setFragment(new TreatmentsBolusFragment());
|
||||||
break;
|
break;
|
||||||
|
case R.id.treatments_extendedboluses:
|
||||||
|
setFragment(new TreatmentsExtendedBolusesFragment());
|
||||||
|
break;
|
||||||
case R.id.treatments_tempbasals:
|
case R.id.treatments_tempbasals:
|
||||||
setFragment(new TreatmentsTemporaryBasalsFragment());
|
setFragment(new TreatmentsTemporaryBasalsFragment());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -321,7 +321,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void extendedBolusStart(ExtendedBolus extendedBolus) {
|
public void extendedBolusStart(ExtendedBolus extendedBolus) {
|
||||||
MainApp.getDbHelper().create(extendedBolus);
|
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -329,7 +329,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
ExtendedBolus extendedBolus = new ExtendedBolus();
|
ExtendedBolus extendedBolus = new ExtendedBolus();
|
||||||
extendedBolus.date = time;
|
extendedBolus.date = time;
|
||||||
extendedBolus.durationInMinutes = 0;
|
extendedBolus.durationInMinutes = 0;
|
||||||
MainApp.getDbHelper().create(extendedBolus);
|
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -368,7 +368,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tempBasalStart(TemporaryBasal tempBasal) {
|
public void tempBasalStart(TemporaryBasal tempBasal) {
|
||||||
MainApp.getDbHelper().createIfNotExists(tempBasal);
|
MainApp.getDbHelper().createOrUpdate(tempBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -376,7 +376,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
||||||
temporaryBasal.date = time;
|
temporaryBasal.date = time;
|
||||||
temporaryBasal.durationInMinutes = 0;
|
temporaryBasal.durationInMinutes = 0;
|
||||||
MainApp.getDbHelper().createIfNotExists(temporaryBasal);
|
MainApp.getDbHelper().createOrUpdate(temporaryBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
package info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.widget.CardView;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.crashlytics.android.answers.Answers;
|
||||||
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
|
import info.nightscout.utils.DateUtil;
|
||||||
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
import info.nightscout.utils.OverlappingIntervals;
|
||||||
|
|
||||||
|
|
||||||
|
public class TreatmentsExtendedBolusesFragment extends Fragment {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(TreatmentsExtendedBolusesFragment.class);
|
||||||
|
|
||||||
|
RecyclerView recyclerView;
|
||||||
|
LinearLayoutManager llm;
|
||||||
|
|
||||||
|
Context context;
|
||||||
|
|
||||||
|
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ExtendedBolusesViewHolder> {
|
||||||
|
|
||||||
|
OverlappingIntervals<ExtendedBolus> extendedBolusList;
|
||||||
|
|
||||||
|
RecyclerViewAdapter(OverlappingIntervals<ExtendedBolus> extendedBolusList) {
|
||||||
|
this.extendedBolusList = extendedBolusList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedBolusesViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_extendedbolus_item, viewGroup, false);
|
||||||
|
return new ExtendedBolusesViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) {
|
||||||
|
ExtendedBolus extendedBolus = extendedBolusList.getReversed(position);
|
||||||
|
if (extendedBolus.isEndingEvent()) {
|
||||||
|
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
|
||||||
|
holder.duration.setText(MainApp.sResources.getString(R.string.stopevent));
|
||||||
|
holder.insulin.setText("");
|
||||||
|
holder.realDuration.setText("");
|
||||||
|
holder.iob.setText("");
|
||||||
|
holder.insulinSoFar.setText("");
|
||||||
|
holder.ratio.setText("");
|
||||||
|
} else {
|
||||||
|
if (extendedBolus.isInProgress()) {
|
||||||
|
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
|
||||||
|
} else {
|
||||||
|
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date) + " - " + DateUtil.timeString(extendedBolus.end()));
|
||||||
|
}
|
||||||
|
holder.duration.setText(DecimalFormatter.to0Decimal(extendedBolus.durationInMinutes) + " min");
|
||||||
|
holder.insulin.setText(DecimalFormatter.to2Decimal(extendedBolus.insulin) + " U");
|
||||||
|
holder.realDuration.setText(DecimalFormatter.to0Decimal(extendedBolus.getRealDuration()) + " min");
|
||||||
|
IobTotal iob = extendedBolus.iobCalc(new Date().getTime());
|
||||||
|
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iob) + " U");
|
||||||
|
holder.insulinSoFar.setText(DecimalFormatter.to2Decimal(extendedBolus.insulinSoFar()) + " U");
|
||||||
|
holder.ratio.setText(DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + " U/h");
|
||||||
|
if (extendedBolus.isInProgress())
|
||||||
|
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
||||||
|
else
|
||||||
|
holder.date.setTextColor(holder.insulin.getCurrentTextColor());
|
||||||
|
if (extendedBolus.iobCalc(new Date().getTime()).iob != 0)
|
||||||
|
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
||||||
|
else
|
||||||
|
holder.iob.setTextColor(holder.insulin.getCurrentTextColor());
|
||||||
|
}
|
||||||
|
holder.remove.setTag(extendedBolus);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return extendedBolusList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||||
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ExtendedBolusesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
CardView cv;
|
||||||
|
TextView date;
|
||||||
|
TextView duration;
|
||||||
|
TextView insulin;
|
||||||
|
TextView realDuration;
|
||||||
|
TextView ratio;
|
||||||
|
TextView insulinSoFar;
|
||||||
|
TextView iob;
|
||||||
|
TextView remove;
|
||||||
|
|
||||||
|
ExtendedBolusesViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
cv = (CardView) itemView.findViewById(R.id.extendedboluses_cardview);
|
||||||
|
date = (TextView) itemView.findViewById(R.id.extendedboluses_date);
|
||||||
|
duration = (TextView) itemView.findViewById(R.id.extendedboluses_duration);
|
||||||
|
insulin = (TextView) itemView.findViewById(R.id.extendedboluses_insulin);
|
||||||
|
realDuration = (TextView) itemView.findViewById(R.id.extendedboluses_realduration);
|
||||||
|
ratio = (TextView) itemView.findViewById(R.id.extendedboluses_ratio);
|
||||||
|
insulinSoFar = (TextView) itemView.findViewById(R.id.extendedboluses_netinsulin);
|
||||||
|
iob = (TextView) itemView.findViewById(R.id.extendedboluses_iob);
|
||||||
|
remove = (TextView) itemView.findViewById(R.id.extendedboluses_remove);
|
||||||
|
remove.setOnClickListener(this);
|
||||||
|
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final ExtendedBolus extendedBolus = (ExtendedBolus) v.getTag();
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.extendedboluses_remove:
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
|
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(extendedBolus.date));
|
||||||
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
final String _id = extendedBolus._id;
|
||||||
|
if (_id != null && !_id.equals("")) {
|
||||||
|
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||||
|
}
|
||||||
|
MainApp.getDbHelper().delete(extendedBolus);
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("RemoveExtendedBolus"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
|
||||||
|
builder.show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.treatments_extendedbolus_fragment, container, false);
|
||||||
|
|
||||||
|
recyclerView = (RecyclerView) view.findViewById(R.id.extendedboluses_recyclerview);
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
llm = new LinearLayoutManager(view.getContext());
|
||||||
|
recyclerView.setLayoutManager(llm);
|
||||||
|
|
||||||
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getConfigBuilder().getExtendedBoluses());
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
context = getContext();
|
||||||
|
|
||||||
|
updateGUI();
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
MainApp.bus().unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
MainApp.bus().register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateGUI() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null && recyclerView != null)
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getConfigBuilder().getExtendedBoluses()), false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -156,11 +156,10 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
|
||||||
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempBasal.date));
|
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempBasal.date));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
// TODO: handle this in NS too
|
final String _id = tempBasal._id;
|
||||||
//final String _id = tempBasal._id;
|
if (_id != null && !_id.equals("")) {
|
||||||
//if (_id != null && !_id.equals("")) {
|
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||||
// MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
}
|
||||||
//}
|
|
||||||
MainApp.getDbHelper().delete(tempBasal);
|
MainApp.getDbHelper().delete(tempBasal);
|
||||||
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,7 +365,7 @@ public class ActionStringHandler {
|
||||||
tempTarget.low = 0;
|
tempTarget.low = 0;
|
||||||
tempTarget.high = 0;
|
tempTarget.high = 0;
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().createIfNotExists(tempTarget);
|
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
||||||
|
|
||||||
//TODO: Nightscout-Treatment for Temp-Target!
|
//TODO: Nightscout-Treatment for Temp-Target!
|
||||||
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="info.nightscout.androidaps.plugins.TreatmentsFromHistory.fragments.TreatmentsExtendedBolusesFragment">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/extendedboluses_recyclerview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</android.support.v7.widget.RecyclerView>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
165
app/src/main/res/layout/treatments_extendedbolus_item.xml
Normal file
165
app/src/main/res/layout/treatments_extendedbolus_item.xml
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/extendedboluses_cardview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
card_view:cardBackgroundColor="?android:colorBackground">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:baselineAligned="true"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
|
||||||
|
<com.joanzapata.iconify.widget.IconTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center_vertical|right"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="{fa-clock-o}" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_date"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="1.1.2000 18:00"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_insulin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:text="150%"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_duration"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:text="30 min"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_realduration_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/tempbasals_realduration_label_string"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_realduration"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:text="10 min"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_netratio_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/tempbasals_netratio_label_string"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_ratio"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:text="0.05 U/h"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_netinsulin_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/tempbasals_netinsulin_label_string"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_netinsulin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:text="0.05 U"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_iob_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:text="@string/tempbasals_iob_label_string"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_iob"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginRight="30dp"
|
||||||
|
android:text="0.12 U"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/extendedboluses_remove"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/overview_quickwizard_item_remove_button"
|
||||||
|
android:textAlignment="viewEnd"
|
||||||
|
android:textColor="@android:color/holo_orange_light" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</android.support.v7.widget.CardView>
|
|
@ -23,6 +23,14 @@
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:text="@string/bolus" />
|
android:text="@string/bolus" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/treatments_extendedboluses"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="@string/extendedbolus" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/treatments_tempbasals"
|
android:id="@+id/treatments_tempbasals"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -614,4 +614,5 @@
|
||||||
<string name="basal_step">Basal Step</string>
|
<string name="basal_step">Basal Step</string>
|
||||||
<string name="bolus_step">Bolus Step</string>
|
<string name="bolus_step">Bolus Step</string>
|
||||||
<string name="stopevent">STOP</string>
|
<string name="stopevent">STOP</string>
|
||||||
|
<string name="extendedbolus">ExtendedBolus</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue