diff --git a/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java index 8ceb9d62..0bf3b0a3 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java @@ -536,7 +536,7 @@ public class DataEntryActivity extends AppCompatActivity { } break; case DragEvent.ACTION_DROP: - View draggedView = (View) event.getLocalState(); + MeasurementView draggedView = (MeasurementView) event.getLocalState(); TableLayout table = (TableLayout) draggedView.getParent(); final int draggedIndex = table.indexOfChild(draggedView); final int targetIndex = table.indexOfChild(view); @@ -545,7 +545,9 @@ public class DataEntryActivity extends AppCompatActivity { // and a view that is moved up is placed before the target view. table.removeView(draggedView); table.addView(draggedView, targetIndex); - MeasurementView.saveMeasurementViewsOrder(table); + dataEntryMeasurements.remove(draggedView); + dataEntryMeasurements.add(targetIndex, draggedView); + MeasurementView.saveMeasurementViewsOrder(getApplicationContext(), dataEntryMeasurements); } break; case DragEvent.ACTION_DRAG_ENDED: diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java index e274b234..3e297de4 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java @@ -144,17 +144,15 @@ public abstract class MeasurementView extends TableLayout { return sorted; } - public static void saveMeasurementViewsOrder(TableLayout tableLayout) { + public static void saveMeasurementViewsOrder(Context context, List measurementViews) { ArrayList order = new ArrayList<>(); - for (int i = 0; i < tableLayout.getChildCount(); ++i) { - MeasurementView view = (MeasurementView) tableLayout.getChildAt(i); - if (view instanceof DateMeasurementView || view instanceof TimeMeasurementView) { + for (MeasurementView measurement : measurementViews) { + if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) { continue; } - order.add(view.getKey()); + order.add(measurement.getKey()); } - PreferenceManager.getDefaultSharedPreferences(tableLayout.getContext()) - .edit() + PreferenceManager.getDefaultSharedPreferences(context).edit() .putString(PREF_MEASUREMENT_ORDER, TextUtils.join(",", order)) .commit(); }