diff --git a/Diaguard/Diaguard.iml b/Diaguard/Diaguard.iml
index 63536d086..66d6309ec 100644
--- a/Diaguard/Diaguard.iml
+++ b/Diaguard/Diaguard.iml
@@ -132,13 +132,16 @@
+
+
+
@@ -150,6 +153,7 @@
+
diff --git a/Diaguard/build.gradle b/Diaguard/build.gradle
index 28a0c37af..53a475e4d 100644
--- a/Diaguard/build.gradle
+++ b/Diaguard/build.gradle
@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
- versionCode 35
- versionName "3.2.0"
+ versionCode 36
+ versionName "3.2.1"
vectorDrawables.useSupportLibrary = true
}
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementAbstractView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementAbstractView.java
index 93f03ec13..7212dabb1 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementAbstractView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementAbstractView.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
@@ -9,6 +10,8 @@
import com.faltenreich.diaguard.data.entity.Meal;
import com.faltenreich.diaguard.data.entity.Measurement;
+import java.lang.reflect.Constructor;
+
import butterknife.ButterKnife;
/**
@@ -46,6 +49,18 @@ public MeasurementAbstractView(Context context, Food food) {
init();
}
+ public MeasurementAbstractView(Context context, Measurement.Category category) {
+ super(context);
+ try {
+ Class clazz = category.toClass();
+ Constructor constructor = clazz.getConstructor();
+ measurement = constructor.newInstance();
+ } catch (Exception exception) {
+ Log.e(TAG, String.format("Could not get newInstance for %s", category.toClass().getSimpleName()));
+ }
+ init();
+ }
+
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementGenericView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementGenericView.java
index d7d0bb027..90fb067c1 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementGenericView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementGenericView.java
@@ -28,7 +28,7 @@ public MeasurementGenericView(Context context, T measurement) {
}
public MeasurementGenericView(Context context, Measurement.Category category) {
- super(context, (T) category.createMeasurement());
+ super(context, category);
}
@Override
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementInsulinView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementInsulinView.java
index e005d260a..5f4ebb483 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementInsulinView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementInsulinView.java
@@ -22,7 +22,7 @@ public class MeasurementInsulinView extends MeasurementAbstractView {
@BindView(R.id.insulin_basal) StickyHintInput inputBasal;
public MeasurementInsulinView(Context context) {
- super(context, new Insulin());
+ super(context, Measurement.Category.INSULIN);
}
public MeasurementInsulinView(Context context, Insulin insulin) {
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementListView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementListView.java
index 72e84094e..a1d1400af 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementListView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementListView.java
@@ -8,9 +8,6 @@
import com.faltenreich.diaguard.data.entity.Food;
import com.faltenreich.diaguard.data.entity.Measurement;
-import com.faltenreich.diaguard.ui.activity.EntryActivity;
-
-import org.joda.time.DateTime;
import java.util.ArrayList;
import java.util.List;
@@ -105,16 +102,10 @@ public void addMeasurement(Food food) {
}
}
- // TODO: Improved performance
public void addMeasurements(List measurements) {
- long start = DateTime.now().getMillis();
-
for (Measurement measurement : measurements) {
addMeasurement(categories.size(), measurement);
}
-
- long end = DateTime.now().getMillis();
- Log.d(EntryActivity.class.getSimpleName(), String.format("Took millis: %d", end - start));
}
public void removeMeasurement(Measurement.Category category) {
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementMealView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementMealView.java
index 5130582d6..62a9831e0 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementMealView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementMealView.java
@@ -18,7 +18,7 @@ public class MeasurementMealView extends MeasurementAbstractView {
@BindView(R.id.list_item_measurement_meal_food_list) FoodInputView foodInputView;
public MeasurementMealView(Context context) {
- super(context, new Meal());
+ super(context, Measurement.Category.MEAL);
}
public MeasurementMealView(Context context, Meal meal) {
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementPressureView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementPressureView.java
index ea851abaa..eb4af96fa 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementPressureView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementPressureView.java
@@ -22,7 +22,7 @@ public class MeasurementPressureView extends MeasurementAbstractView {
StickyHintInput diastolic;
public MeasurementPressureView(Context context) {
- super(context, new Pressure());
+ super(context, Measurement.Category.PRESSURE);
}
public MeasurementPressureView(Context context, Pressure pressure) {
diff --git a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementView.java b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementView.java
index b485b38f7..6a99b036b 100644
--- a/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementView.java
+++ b/Diaguard/src/main/java/com/faltenreich/diaguard/ui/view/entry/MeasurementView.java
@@ -98,18 +98,27 @@ private void initData() {
textViewCategory.setText(categoryName);
buttonRemove.setContentDescription(String.format(getContext().getString(R.string.remove_placeholder), categoryName));
+ boolean isUpdating = measurement != null;
switch (category) {
case INSULIN:
- content.addView(new MeasurementInsulinView(getContext(), measurement != null ? (Insulin) measurement : null));
+ content.addView(isUpdating ?
+ new MeasurementInsulinView(getContext(), (Insulin) measurement) :
+ new MeasurementInsulinView(getContext()));
break;
case MEAL:
- content.addView(measurement != null ? new MeasurementMealView(getContext(), (Meal) measurement) : new MeasurementMealView(getContext(), food));
+ content.addView(isUpdating ?
+ new MeasurementMealView(getContext(), (Meal) measurement) :
+ new MeasurementMealView(getContext(), food));
break;
case PRESSURE:
- content.addView(new MeasurementPressureView(getContext(), measurement != null ? (Pressure) measurement : null));
+ content.addView(isUpdating ?
+ new MeasurementPressureView(getContext(), (Pressure) measurement) :
+ new MeasurementPressureView(getContext()));
break;
default:
- content.addView(measurement != null ? new MeasurementGenericView<>(getContext(), measurement) : new MeasurementGenericView<>(getContext(), category));
+ content.addView(isUpdating ?
+ new MeasurementGenericView<>(getContext(), measurement) :
+ new MeasurementGenericView<>(getContext(), category));
}
}