mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 03:30:30 +02:00
Sort List of views as well and pass that when saving order
This commit is contained in:
@@ -536,7 +536,7 @@ public class DataEntryActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DragEvent.ACTION_DROP:
|
case DragEvent.ACTION_DROP:
|
||||||
View draggedView = (View) event.getLocalState();
|
MeasurementView draggedView = (MeasurementView) event.getLocalState();
|
||||||
TableLayout table = (TableLayout) draggedView.getParent();
|
TableLayout table = (TableLayout) draggedView.getParent();
|
||||||
final int draggedIndex = table.indexOfChild(draggedView);
|
final int draggedIndex = table.indexOfChild(draggedView);
|
||||||
final int targetIndex = table.indexOfChild(view);
|
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.
|
// and a view that is moved up is placed before the target view.
|
||||||
table.removeView(draggedView);
|
table.removeView(draggedView);
|
||||||
table.addView(draggedView, targetIndex);
|
table.addView(draggedView, targetIndex);
|
||||||
MeasurementView.saveMeasurementViewsOrder(table);
|
dataEntryMeasurements.remove(draggedView);
|
||||||
|
dataEntryMeasurements.add(targetIndex, draggedView);
|
||||||
|
MeasurementView.saveMeasurementViewsOrder(getApplicationContext(), dataEntryMeasurements);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DragEvent.ACTION_DRAG_ENDED:
|
case DragEvent.ACTION_DRAG_ENDED:
|
||||||
|
@@ -144,17 +144,15 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveMeasurementViewsOrder(TableLayout tableLayout) {
|
public static void saveMeasurementViewsOrder(Context context, List<MeasurementView> measurementViews) {
|
||||||
ArrayList<String> order = new ArrayList<>();
|
ArrayList<String> order = new ArrayList<>();
|
||||||
for (int i = 0; i < tableLayout.getChildCount(); ++i) {
|
for (MeasurementView measurement : measurementViews) {
|
||||||
MeasurementView view = (MeasurementView) tableLayout.getChildAt(i);
|
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
|
||||||
if (view instanceof DateMeasurementView || view instanceof TimeMeasurementView) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
order.add(view.getKey());
|
order.add(measurement.getKey());
|
||||||
}
|
}
|
||||||
PreferenceManager.getDefaultSharedPreferences(tableLayout.getContext())
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
.edit()
|
|
||||||
.putString(PREF_MEASUREMENT_ORDER, TextUtils.join(",", order))
|
.putString(PREF_MEASUREMENT_ORDER, TextUtils.join(",", order))
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user