diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java index 9b38dbcbe9..5506d32471 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java @@ -128,4 +128,22 @@ public class Food { units = other.units; gi = other.gi; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("_id=" + _id + ";"); + sb.append("isValid=" + isValid + ";"); + sb.append("name=" + name + ";"); + sb.append("category=" + category + ";"); + sb.append("subcategory=" + subcategory + ";"); + sb.append("portion=" + portion + ";"); + sb.append("carbs=" + carbs + ";"); + sb.append("protein=" + protein + ";"); + sb.append("energy=" + energy + ";"); + sb.append("units=" + units + ";"); + sb.append("gi=" + gi + ";"); + + return sb.toString(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java index 617c975825..c3028461ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java @@ -53,7 +53,7 @@ public class FoodService extends OrmLiteBaseService { /** * This method is a simple re-implementation of the database create and up/downgrade functionality * in SQLiteOpenHelper#getDatabaseLocked method. - * + *

* It is implemented to be able to late initialize separate plugins of the application. */ protected void dbInitialize() { @@ -145,10 +145,10 @@ public class FoodService extends OrmLiteBaseService { /** * A place to centrally register events to be posted, if any data changed. * This should be implemented in an abstract service-class. - * + *

* We do need to make sure, that ICallback is extended to be able to handle multiple * events, or handle a list of events. - * + *

* on some methods the earliestDataChange event is handled separatly, in that it is checked if it is * set to null by another event already (eg. scheduleExtendedBolusChange). * @@ -227,8 +227,7 @@ public class FoodService extends OrmLiteBaseService { public void createFoodFromJsonIfNotExists(JSONArray array) { try { - for(int n = 0; n < array.length(); n++) - { + for (int n = 0; n < array.length(); n++) { JSONObject json = array.getJSONObject(n); Food food = Food.createFromJson(json); this.createFoodFromJsonIfNotExists(food); @@ -252,9 +251,8 @@ public class FoodService extends OrmLiteBaseService { } public void deleteNS(JSONArray array) { - try { - for(int n = 0; n < array.length(); n++) - { + try { + for (int n = 0; n < array.length(); n++) { JSONObject json = array.getJSONObject(n); this.deleteNS(json); } @@ -265,7 +263,7 @@ public class FoodService extends OrmLiteBaseService { /** * deletes an entry by its NS Id. - * + *

* Basically a convenience method for findByNSId and delete. * * @param _id @@ -280,7 +278,7 @@ public class FoodService extends OrmLiteBaseService { /** * deletes the food and sends the foodChange Event - * + *

* should be moved ot a Service * * @param food @@ -314,10 +312,10 @@ public class FoodService extends OrmLiteBaseService { } else { return false; } + } else { + this.createOrUpdate(food); + return true; } - } else { - this.createOrUpdate(food); - return true; } return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index 1ef71c2f75..fa96fdc967 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -572,22 +572,20 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods")); for (Integer index = 0; index < foods.length(); index++) { JSONObject jsonFood = foods.getJSONObject(index); - NSTreatment treatment = new NSTreatment(jsonFood); // remove from upload queue if Ack is failing UploadQueue.removeID(jsonFood); - //Find latest date in treatment - if (treatment.getMills() != null && treatment.getMills() < System.currentTimeMillis()) - if (treatment.getMills() > latestDateInReceivedData) - latestDateInReceivedData = treatment.getMills(); - if (treatment.getAction() == null) { + String action = null; + if (jsonFood.has("action")) + action = jsonFood.getString("action"); + + if (action == null) { addedFoods.put(jsonFood); - } else if (treatment.getAction().equals("update")) { + } else if (action.equals("update")) { updatedFoods.put(jsonFood); - } else if (treatment.getAction().equals("remove")) { - if (treatment.getMills() != null && treatment.getMills() > System.currentTimeMillis() - 24 * 60 * 60 * 1000L) // handle 1 day old deletions only - removedFoods.put(jsonFood); + } else if (action.equals("remove")) { + removedFoods.put(jsonFood); } } if (removedFoods.length() > 0) { @@ -600,18 +598,6 @@ public class NSClientService extends Service { BroadcastFood.handleNewFood(addedFoods, MainApp.instance().getApplicationContext(), isDelta); } } - if (data.has("")) { - JSONArray foods = data.getJSONArray("food"); - if (foods.length() > 0) { - MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods")); - for (Integer index = 0; index < foods.length(); index++) { - JSONObject jsonFood = foods.getJSONObject(index); - // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonFood); - } - BroadcastDeviceStatus.handleNewFoods(foods, MainApp.instance().getApplicationContext(), isDelta); - } - } if (data.has("mbgs")) { JSONArray mbgs = data.getJSONArray("mbgs"); if (mbgs.length() > 0) diff --git a/app/src/main/res/layout/food_fragment.xml b/app/src/main/res/layout/food_fragment.xml index 7b42eff11f..f204677968 100644 --- a/app/src/main/res/layout/food_fragment.xml +++ b/app/src/main/res/layout/food_fragment.xml @@ -50,7 +50,7 @@ + android:text="@string/category" /> + android:text="@string/subcategory" /> Opravdu chcete přečíst historii z pumpy a nést důsledky z toho vyplývající? Nedostatek inzulínu pro takovýto bolus Chyba spuštění extended bolusu + Podkategorie + Kategorie diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 554b7f759f..4378d9a632 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -861,5 +861,7 @@ Recovering from connection loss Not enough insulin for bolus left in reservoir Extended bolus delivery error + Category + Subcategory