1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-29 19:20:36 +02:00

Sort List of views as well and pass that when saving order

This commit is contained in:
Erik Johansson
2018-02-21 00:18:57 +01:00
parent b2eb11380f
commit 660b017741
2 changed files with 9 additions and 9 deletions

View File

@@ -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:

View File

@@ -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<MeasurementView> measurementViews) {
ArrayList<String> 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();
}