food code cleanup
This commit is contained in:
parent
f68d8f1626
commit
38999d6598
6 changed files with 43 additions and 37 deletions
|
@ -128,4 +128,22 @@ public class Food {
|
||||||
units = other.units;
|
units = other.units;
|
||||||
gi = other.gi;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
/**
|
/**
|
||||||
* This method is a simple re-implementation of the database create and up/downgrade functionality
|
* This method is a simple re-implementation of the database create and up/downgrade functionality
|
||||||
* in SQLiteOpenHelper#getDatabaseLocked method.
|
* in SQLiteOpenHelper#getDatabaseLocked method.
|
||||||
*
|
* <p>
|
||||||
* It is implemented to be able to late initialize separate plugins of the application.
|
* It is implemented to be able to late initialize separate plugins of the application.
|
||||||
*/
|
*/
|
||||||
protected void dbInitialize() {
|
protected void dbInitialize() {
|
||||||
|
@ -145,10 +145,10 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
/**
|
/**
|
||||||
* A place to centrally register events to be posted, if any data changed.
|
* A place to centrally register events to be posted, if any data changed.
|
||||||
* This should be implemented in an abstract service-class.
|
* This should be implemented in an abstract service-class.
|
||||||
*
|
* <p>
|
||||||
* We do need to make sure, that ICallback is extended to be able to handle multiple
|
* We do need to make sure, that ICallback is extended to be able to handle multiple
|
||||||
* events, or handle a list of events.
|
* events, or handle a list of events.
|
||||||
*
|
* <p>
|
||||||
* on some methods the earliestDataChange event is handled separatly, in that it is checked if it is
|
* 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).
|
* set to null by another event already (eg. scheduleExtendedBolusChange).
|
||||||
*
|
*
|
||||||
|
@ -227,8 +227,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
public void createFoodFromJsonIfNotExists(JSONArray array) {
|
public void createFoodFromJsonIfNotExists(JSONArray array) {
|
||||||
try {
|
try {
|
||||||
for(int n = 0; n < array.length(); n++)
|
for (int n = 0; n < array.length(); n++) {
|
||||||
{
|
|
||||||
JSONObject json = array.getJSONObject(n);
|
JSONObject json = array.getJSONObject(n);
|
||||||
Food food = Food.createFromJson(json);
|
Food food = Food.createFromJson(json);
|
||||||
this.createFoodFromJsonIfNotExists(food);
|
this.createFoodFromJsonIfNotExists(food);
|
||||||
|
@ -252,9 +251,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteNS(JSONArray array) {
|
public void deleteNS(JSONArray array) {
|
||||||
try {
|
try {
|
||||||
for(int n = 0; n < array.length(); n++)
|
for (int n = 0; n < array.length(); n++) {
|
||||||
{
|
|
||||||
JSONObject json = array.getJSONObject(n);
|
JSONObject json = array.getJSONObject(n);
|
||||||
this.deleteNS(json);
|
this.deleteNS(json);
|
||||||
}
|
}
|
||||||
|
@ -265,7 +263,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes an entry by its NS Id.
|
* deletes an entry by its NS Id.
|
||||||
*
|
* <p>
|
||||||
* Basically a convenience method for findByNSId and delete.
|
* Basically a convenience method for findByNSId and delete.
|
||||||
*
|
*
|
||||||
* @param _id
|
* @param _id
|
||||||
|
@ -280,7 +278,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes the food and sends the foodChange Event
|
* deletes the food and sends the foodChange Event
|
||||||
*
|
* <p>
|
||||||
* should be moved ot a Service
|
* should be moved ot a Service
|
||||||
*
|
*
|
||||||
* @param food
|
* @param food
|
||||||
|
@ -314,10 +312,10 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.createOrUpdate(food);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.createOrUpdate(food);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -572,22 +572,20 @@ public class NSClientService extends Service {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
||||||
for (Integer index = 0; index < foods.length(); index++) {
|
for (Integer index = 0; index < foods.length(); index++) {
|
||||||
JSONObject jsonFood = foods.getJSONObject(index);
|
JSONObject jsonFood = foods.getJSONObject(index);
|
||||||
NSTreatment treatment = new NSTreatment(jsonFood);
|
|
||||||
|
|
||||||
// remove from upload queue if Ack is failing
|
// remove from upload queue if Ack is failing
|
||||||
UploadQueue.removeID(jsonFood);
|
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);
|
addedFoods.put(jsonFood);
|
||||||
} else if (treatment.getAction().equals("update")) {
|
} else if (action.equals("update")) {
|
||||||
updatedFoods.put(jsonFood);
|
updatedFoods.put(jsonFood);
|
||||||
} else if (treatment.getAction().equals("remove")) {
|
} else if (action.equals("remove")) {
|
||||||
if (treatment.getMills() != null && treatment.getMills() > System.currentTimeMillis() - 24 * 60 * 60 * 1000L) // handle 1 day old deletions only
|
removedFoods.put(jsonFood);
|
||||||
removedFoods.put(jsonFood);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (removedFoods.length() > 0) {
|
if (removedFoods.length() > 0) {
|
||||||
|
@ -600,18 +598,6 @@ public class NSClientService extends Service {
|
||||||
BroadcastFood.handleNewFood(addedFoods, MainApp.instance().getApplicationContext(), isDelta);
|
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")) {
|
if (data.has("mbgs")) {
|
||||||
JSONArray mbgs = data.getJSONArray("mbgs");
|
JSONArray mbgs = data.getJSONArray("mbgs");
|
||||||
if (mbgs.length() > 0)
|
if (mbgs.length() > 0)
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Category" />
|
android:text="@string/category" />
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/food_category"
|
android:id="@+id/food_category"
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Subcategory" />
|
android:text="@string/subcategory" />
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/food_subcategory"
|
android:id="@+id/food_subcategory"
|
||||||
|
|
|
@ -779,4 +779,6 @@
|
||||||
<string name="combo_read_full_history_confirmation">Opravdu chcete přečíst historii z pumpy a nést důsledky z toho vyplývající?</string>
|
<string name="combo_read_full_history_confirmation">Opravdu chcete přečíst historii z pumpy a nést důsledky z toho vyplývající?</string>
|
||||||
<string name="combo_reservoir_level_insufficient_for_bolus">Nedostatek inzulínu pro takovýto bolus</string>
|
<string name="combo_reservoir_level_insufficient_for_bolus">Nedostatek inzulínu pro takovýto bolus</string>
|
||||||
<string name="extendedbolusdeliveryerror">Chyba spuštění extended bolusu</string>
|
<string name="extendedbolusdeliveryerror">Chyba spuštění extended bolusu</string>
|
||||||
|
<string name="subcategory">Podkategorie</string>
|
||||||
|
<string name="category">Kategorie</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -861,5 +861,7 @@
|
||||||
<string name="combo_error_bolus_recovery_progress">Recovering from connection loss</string>
|
<string name="combo_error_bolus_recovery_progress">Recovering from connection loss</string>
|
||||||
<string name="combo_reservoir_level_insufficient_for_bolus">Not enough insulin for bolus left in reservoir</string>
|
<string name="combo_reservoir_level_insufficient_for_bolus">Not enough insulin for bolus left in reservoir</string>
|
||||||
<string name="extendedbolusdeliveryerror">Extended bolus delivery error</string>
|
<string name="extendedbolusdeliveryerror">Extended bolus delivery error</string>
|
||||||
|
<string name="category">Category</string>
|
||||||
|
<string name="subcategory">Subcategory</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue