food code cleanup

This commit is contained in:
Milos Kozak 2018-03-12 10:53:23 +01:00
parent f68d8f1626
commit 38999d6598
6 changed files with 43 additions and 37 deletions

View file

@ -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();
}
}

View file

@ -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
* in SQLiteOpenHelper#getDatabaseLocked method.
*
* <p>
* 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<DatabaseHelper> {
/**
* A place to centrally register events to be posted, if any data changed.
* 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
* 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
* set to null by another event already (eg. scheduleExtendedBolusChange).
*
@ -227,8 +227,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
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);
@ -253,8 +252,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
public void deleteNS(JSONArray array) {
try {
for(int n = 0; n < array.length(); n++)
{
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<DatabaseHelper> {
/**
* deletes an entry by its NS Id.
*
* <p>
* Basically a convenience method for findByNSId and delete.
*
* @param _id
@ -280,7 +278,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
/**
* deletes the food and sends the foodChange Event
*
* <p>
* should be moved ot a Service
*
* @param food
@ -314,11 +312,11 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
} else {
return false;
}
}
} else {
this.createOrUpdate(food);
return true;
}
}
return false;
}

View file

@ -572,21 +572,19 @@ 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
} else if (action.equals("remove")) {
removedFoods.put(jsonFood);
}
}
@ -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)

View file

@ -50,7 +50,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category" />
android:text="@string/category" />
<Spinner
android:id="@+id/food_category"
@ -67,7 +67,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subcategory" />
android:text="@string/subcategory" />
<Spinner
android:id="@+id/food_subcategory"

View file

@ -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_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="subcategory">Podkategorie</string>
<string name="category">Kategorie</string>
</resources>

View file

@ -861,5 +861,7 @@
<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="extendedbolusdeliveryerror">Extended bolus delivery error</string>
<string name="category">Category</string>
<string name="subcategory">Subcategory</string>
</resources>